1 16 package org.apache.myfaces.component.html.ext; 17 18 import org.apache.myfaces.component.UserRoleAware; 19 import org.apache.myfaces.component.UserRoleUtils; 20 import org.apache.myfaces.component.html.util.HtmlComponentUtils; 21 22 import javax.faces.context.FacesContext; 23 import javax.faces.el.ValueBinding; 24 25 45 public class HtmlSelectOneMenu 46 extends javax.faces.component.html.HtmlSelectOneMenu 47 implements UserRoleAware 48 { 49 public String getClientId(FacesContext context) 50 { 51 String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context); 52 if (clientId == null) 53 { 54 clientId = super.getClientId(context); 55 } 56 57 return clientId; 58 } 59 60 62 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlSelectOneMenu"; 63 64 private String _enabledOnUserRole = null; 65 private String _visibleOnUserRole = null; 66 67 public HtmlSelectOneMenu() 68 { 69 } 70 71 72 public void setEnabledOnUserRole(String enabledOnUserRole) 73 { 74 _enabledOnUserRole = enabledOnUserRole; 75 } 76 77 public String getEnabledOnUserRole() 78 { 79 if (_enabledOnUserRole != null) return _enabledOnUserRole; 80 ValueBinding vb = getValueBinding("enabledOnUserRole"); 81 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 82 } 83 84 public void setVisibleOnUserRole(String visibleOnUserRole) 85 { 86 _visibleOnUserRole = visibleOnUserRole; 87 } 88 89 public String getVisibleOnUserRole() 90 { 91 if (_visibleOnUserRole != null) return _visibleOnUserRole; 92 ValueBinding vb = getValueBinding("visibleOnUserRole"); 93 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 94 } 95 96 97 public boolean isRendered() 98 { 99 if (!UserRoleUtils.isVisibleOnUserRole(this)) return false; 100 return super.isRendered(); 101 } 102 103 public Object saveState(FacesContext context) 104 { 105 Object values[] = new Object [3]; 106 values[0] = super.saveState(context); 107 values[1] = _enabledOnUserRole; 108 values[2] = _visibleOnUserRole; 109 return ((Object ) (values)); 110 } 111 112 public void restoreState(FacesContext context, Object state) 113 { 114 Object values[] = (Object [])state; 115 super.restoreState(context, values[0]); 116 _enabledOnUserRole = (String )values[1]; 117 _visibleOnUserRole = (String )values[2]; 118 } 119 } 121 | Popular Tags |