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