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 60 public class HtmlMessage 61 extends javax.faces.component.html.HtmlMessage 62 implements UserRoleAware 63 { 64 public String getClientId(FacesContext context) 65 { 66 String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context); 67 if (clientId == null) 68 { 69 clientId = super.getClientId(context); 70 } 71 72 return clientId; 73 } 74 75 77 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlMessage"; 78 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Message"; 79 80 private String _summaryFormat = null; 81 private String _detailFormat = null; 82 private String _enabledOnUserRole = null; 83 private String _visibleOnUserRole = null; 84 private Boolean _replaceIdWithLabel = null; 85 86 public HtmlMessage() 87 { 88 setRendererType(DEFAULT_RENDERER_TYPE); 89 } 90 91 92 public void setSummaryFormat(String summaryFormat) 93 { 94 _summaryFormat = summaryFormat; 95 } 96 97 public String getSummaryFormat() 98 { 99 if (_summaryFormat != null) return _summaryFormat; 100 ValueBinding vb = getValueBinding("summaryFormat"); 101 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 102 } 103 104 public void setDetailFormat(String detailFormat) 105 { 106 _detailFormat = detailFormat; 107 } 108 109 public String getDetailFormat() 110 { 111 if (_detailFormat != null) return _detailFormat; 112 ValueBinding vb = getValueBinding("detailFormat"); 113 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 114 } 115 116 public void setEnabledOnUserRole(String enabledOnUserRole) 117 { 118 _enabledOnUserRole = enabledOnUserRole; 119 } 120 121 public String getEnabledOnUserRole() 122 { 123 if (_enabledOnUserRole != null) return _enabledOnUserRole; 124 ValueBinding vb = getValueBinding("enabledOnUserRole"); 125 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 126 } 127 128 public void setVisibleOnUserRole(String visibleOnUserRole) 129 { 130 _visibleOnUserRole = visibleOnUserRole; 131 } 132 133 public String getVisibleOnUserRole() 134 { 135 if (_visibleOnUserRole != null) return _visibleOnUserRole; 136 ValueBinding vb = getValueBinding("visibleOnUserRole"); 137 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 138 } 139 140 public void setReplaceIdWithLabel(boolean replaceIdWithLabel) 141 { 142 _replaceIdWithLabel = Boolean.valueOf(replaceIdWithLabel); 143 } 144 145 public boolean isReplaceIdWithLabel() 146 { 147 if (_replaceIdWithLabel != null) return _replaceIdWithLabel.booleanValue(); 148 ValueBinding vb = getValueBinding("replaceIdWithLabel"); 149 Boolean v = vb != null ? (Boolean )vb.getValue(getFacesContext()) : null; 150 return v != null ? v.booleanValue() : false; 151 } 152 153 154 public boolean isRendered() 155 { 156 if (!UserRoleUtils.isVisibleOnUserRole(this)) return false; 157 return super.isRendered(); 158 } 159 160 public Object saveState(FacesContext context) 161 { 162 Object values[] = new Object [6]; 163 values[0] = super.saveState(context); 164 values[1] = _summaryFormat; 165 values[2] = _detailFormat; 166 values[3] = _enabledOnUserRole; 167 values[4] = _visibleOnUserRole; 168 values[5] = _replaceIdWithLabel; 169 return ((Object ) (values)); 170 } 171 172 public void restoreState(FacesContext context, Object state) 173 { 174 Object values[] = (Object [])state; 175 super.restoreState(context, values[0]); 176 _summaryFormat = (String )values[1]; 177 _detailFormat = (String )values[2]; 178 _enabledOnUserRole = (String )values[3]; 179 _visibleOnUserRole = (String )values[4]; 180 _replaceIdWithLabel = (Boolean )values[5]; 181 } 182 } 184 | Popular Tags |