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 30 public class HtmlMessages 31 extends javax.faces.component.html.HtmlMessages 32 implements UserRoleAware 33 { 34 public String getClientId(FacesContext context) 35 { 36 String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context); 37 if (clientId == null) 38 { 39 clientId = super.getClientId(context); 40 } 41 42 return clientId; 43 } 44 45 47 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlMessages"; 48 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Messages"; 49 50 private String _summaryFormat = null; 51 private String _globalSummaryFormat = null; 52 private String _detailFormat = null; 53 private String _enabledOnUserRole = null; 54 private String _visibleOnUserRole = null; 55 private Boolean _replaceIdWithLabel = null; 56 57 public HtmlMessages() 58 { 59 setRendererType(DEFAULT_RENDERER_TYPE); 60 } 61 62 63 public void setSummaryFormat(String summaryFormat) 64 { 65 _summaryFormat = summaryFormat; 66 } 67 68 public String getSummaryFormat() 69 { 70 if (_summaryFormat != null) return _summaryFormat; 71 ValueBinding vb = getValueBinding("summaryFormat"); 72 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 73 } 74 75 public void setGlobalSummaryFormat(String globalSummaryFormat) 76 { 77 _globalSummaryFormat = globalSummaryFormat; 78 } 79 80 public String getGlobalSummaryFormat() 81 { 82 if (_globalSummaryFormat != null) return _globalSummaryFormat; 83 ValueBinding vb = getValueBinding("globalSummaryFormat"); 84 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 85 } 86 87 public void setDetailFormat(String detailFormat) 88 { 89 _detailFormat = detailFormat; 90 } 91 92 public String getDetailFormat() 93 { 94 if (_detailFormat != null) return _detailFormat; 95 ValueBinding vb = getValueBinding("detailFormat"); 96 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 97 } 98 99 public void setEnabledOnUserRole(String enabledOnUserRole) 100 { 101 _enabledOnUserRole = enabledOnUserRole; 102 } 103 104 public String getEnabledOnUserRole() 105 { 106 if (_enabledOnUserRole != null) return _enabledOnUserRole; 107 ValueBinding vb = getValueBinding("enabledOnUserRole"); 108 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 109 } 110 111 public void setVisibleOnUserRole(String visibleOnUserRole) 112 { 113 _visibleOnUserRole = visibleOnUserRole; 114 } 115 116 public String getVisibleOnUserRole() 117 { 118 if (_visibleOnUserRole != null) return _visibleOnUserRole; 119 ValueBinding vb = getValueBinding("visibleOnUserRole"); 120 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 121 } 122 123 public void setReplaceIdWithLabel(boolean replaceIdWithLabel) 124 { 125 _replaceIdWithLabel = Boolean.valueOf(replaceIdWithLabel); 126 } 127 128 public boolean isReplaceIdWithLabel() 129 { 130 if (_replaceIdWithLabel != null) return _replaceIdWithLabel.booleanValue(); 131 ValueBinding vb = getValueBinding("replaceIdWithLabel"); 132 Boolean v = vb != null ? (Boolean )vb.getValue(getFacesContext()) : null; 133 return v != null ? v.booleanValue() : false; 134 } 135 136 137 public boolean isRendered() 138 { 139 if (!UserRoleUtils.isVisibleOnUserRole(this)) return false; 140 return super.isRendered(); 141 } 142 143 public Object saveState(FacesContext context) 144 { 145 Object values[] = new Object [7]; 146 values[0] = super.saveState(context); 147 values[1] = _summaryFormat; 148 values[2] = _globalSummaryFormat; 149 values[3] = _detailFormat; 150 values[4] = _enabledOnUserRole; 151 values[5] = _visibleOnUserRole; 152 values[6] = _replaceIdWithLabel; 153 return ((Object ) (values)); 154 } 155 156 public void restoreState(FacesContext context, Object state) 157 { 158 Object values[] = (Object [])state; 159 super.restoreState(context, values[0]); 160 _summaryFormat = (String )values[1]; 161 _globalSummaryFormat = (String )values[2]; 162 _detailFormat = (String )values[3]; 163 _enabledOnUserRole = (String )values[4]; 164 _visibleOnUserRole = (String )values[5]; 165 _replaceIdWithLabel = (Boolean )values[6]; 166 } 167 } 169 | Popular Tags |