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