1 16 package org.apache.myfaces.custom.navmenu; 17 18 import org.apache.myfaces.component.UserRoleUtils; 19 import org.apache.myfaces.component.UserRoleAware; 20 21 import javax.faces.component.UISelectItem; 22 import javax.faces.el.ValueBinding; 23 import javax.faces.context.FacesContext; 24 25 39 public class UINavigationMenuItem 40 extends UISelectItem 41 implements UserRoleAware 42 { 43 44 45 47 public static final String COMPONENT_TYPE = "org.apache.myfaces.NavigationMenuItem"; 48 public static final String COMPONENT_FAMILY = "javax.faces.SelectItem"; 49 50 private String _icon = null; 51 private Boolean _split = null; 52 private String _action = null; 53 private String _enabledOnUserRole = null; 54 private String _visibleOnUserRole = null; 55 56 public UINavigationMenuItem() 57 { 58 } 59 60 public String getFamily() 61 { 62 return COMPONENT_FAMILY; 63 } 64 65 public void setIcon(String icon) 66 { 67 _icon = icon; 68 } 69 70 public String getIcon() 71 { 72 if (_icon != null) return _icon; 73 ValueBinding vb = getValueBinding("icon"); 74 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 75 } 76 77 public void setSplit(boolean split) 78 { 79 _split = Boolean.valueOf(split); 80 } 81 82 public boolean isSplit() 83 { 84 if (_split != null) return _split.booleanValue(); 85 ValueBinding vb = getValueBinding("split"); 86 Boolean v = vb != null ? (Boolean )vb.getValue(getFacesContext()) : null; 87 return v != null ? v.booleanValue() : false; 88 } 89 90 public void setAction(String action) 91 { 92 _action = action; 93 } 94 95 public String getAction() 96 { 97 if (_action != null) return _action; 98 ValueBinding vb = getValueBinding("action"); 99 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 100 } 101 102 public void setEnabledOnUserRole(String enabledOnUserRole) 103 { 104 _enabledOnUserRole = enabledOnUserRole; 105 } 106 107 public String getEnabledOnUserRole() 108 { 109 if (_enabledOnUserRole != null) return _enabledOnUserRole; 110 ValueBinding vb = getValueBinding("enabledOnUserRole"); 111 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 112 } 113 114 public void setVisibleOnUserRole(String visibleOnUserRole) 115 { 116 _visibleOnUserRole = visibleOnUserRole; 117 } 118 119 public String getVisibleOnUserRole() 120 { 121 if (_visibleOnUserRole != null) return _visibleOnUserRole; 122 ValueBinding vb = getValueBinding("visibleOnUserRole"); 123 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 124 } 125 126 127 public boolean isRendered() 128 { 129 if (!UserRoleUtils.isVisibleOnUserRole(this)) return false; 130 return super.isRendered(); 131 } 132 133 public Object saveState(FacesContext context) 134 { 135 Object values[] = new Object [6]; 136 values[0] = super.saveState(context); 137 values[1] = _icon; 138 values[2] = _split; 139 values[3] = _action; 140 values[4] = _enabledOnUserRole; 141 values[5] = _visibleOnUserRole; 142 return ((Object ) (values)); 143 } 144 145 public void restoreState(FacesContext context, Object state) 146 { 147 Object values[] = (Object [])state; 148 super.restoreState(context, values[0]); 149 _icon = (String )values[1]; 150 _split = (Boolean )values[2]; 151 _action = (String )values[3]; 152 _enabledOnUserRole = (String )values[4]; 153 _visibleOnUserRole = (String )values[5]; 154 } 155 } 157 | Popular Tags |