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