1 33 34 package com.icesoft.faces.component.panelstack; 35 36 import com.icesoft.faces.component.CSS_DEFAULT; 37 import com.icesoft.faces.component.ext.taglib.Util; 38 39 import javax.faces.component.html.HtmlPanelGroup; 40 import javax.faces.component.UIComponent; 41 import javax.faces.context.FacesContext; 42 import javax.faces.el.ValueBinding; 43 import javax.faces.event.PhaseId; 44 import java.util.Iterator ; 45 46 47 56 public class PanelStack extends HtmlPanelGroup { 57 58 public static final String COMPONENT_TYPE = "com.icesoft.faces.PanelStack"; 59 public static final String COMPONENT_FAMILY = "javax.faces.Panel"; 60 private static final String DEFAULT_RENDERER_TYPE = 61 "com.icesoft.faces.PanelStack"; 62 private String style = null; 63 private String selectedPanel = null; 64 private String styleClass = null; 65 private String renderedOnUserRole = null; 66 67 public PanelStack() { 68 setRendererType(DEFAULT_RENDERER_TYPE); 69 } 70 71 75 public String getFamily() { 76 return COMPONENT_FAMILY; 77 } 78 79 82 public void setStyle(String style) { 83 this.style = style; 84 } 85 86 89 public String getStyle() { 90 if (style != null) { 91 return style; 92 } 93 ValueBinding vb = getValueBinding("style"); 94 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 95 } 96 97 100 public void setSelectedPanel(String selectedPanel) { 101 this.selectedPanel = selectedPanel; 102 } 103 104 107 public String getSelectedPanel() { 108 if (selectedPanel != null) { 109 return selectedPanel; 110 } 111 ValueBinding vb = getValueBinding("selectedPanel"); 112 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 113 } 114 115 118 public boolean isRendered() { 119 if (!Util.isRenderedOnUserRole(this)) { 120 return false; 121 } 122 return super.isRendered(); 123 } 124 125 128 public void setStyleClass(String styleClass) { 129 this.styleClass = styleClass; 130 } 131 132 135 public String getStyleClass() { 136 return Util.getQualifiedStyleClass(this, 137 styleClass, 138 CSS_DEFAULT.PANEL_STACK_BASE, 139 "styleClass"); 140 } 141 142 145 public void setRenderedOnUserRole(String renderedOnUserRole) { 146 this.renderedOnUserRole = renderedOnUserRole; 147 } 148 149 152 public String getRenderedOnUserRole() { 153 if (renderedOnUserRole != null) { 154 return renderedOnUserRole; 155 } 156 ValueBinding vb = getValueBinding("renderedOnUserRole"); 157 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 158 } 159 160 163 public String getRowClass() { 164 return Util.getQualifiedStyleClass(this, CSS_DEFAULT.PANEL_STACK_ROW); 165 } 166 167 170 public String getColumnClass() { 171 return Util.getQualifiedStyleClass(this, CSS_DEFAULT.PANEL_STACK_COL); 172 } 173 174 178 public Object saveState(FacesContext context) { 179 Object values[] = new Object [4]; 180 values[0] = super.saveState(context); 181 values[1] = selectedPanel; 182 values[2] = styleClass; 183 values[3] = style; 184 return ((Object ) (values)); 185 } 186 187 191 public void restoreState(FacesContext context, Object state) { 192 Object values[] = (Object []) state; 193 super.restoreState(context, values[0]); 194 selectedPanel = (String ) values[1]; 195 styleClass = (String ) values[2]; 196 style = (String ) values[3]; 197 } 198 199 200 public static final String LAST_SELECTED_PANEL = "PanelStack-lastPanel"; 201 205 public void applyPhase(FacesContext context, PhaseId phaseId) { 206 if (context == null) { 207 throw new NullPointerException ("Null context in PanelTabSet"); 208 } 209 Iterator it = getFacetsAndChildren(); 210 211 while (it.hasNext()) { 212 UIComponent childOrFacet = 213 (UIComponent) it.next(); 214 String selectedPanel = getSelectedPanel(); 215 String lastSelectedPanel = (String ) context.getExternalContext().getRequestMap().get(LAST_SELECTED_PANEL + getClientId(context)); 216 boolean changed = !selectedPanel.equals(lastSelectedPanel); 217 if (lastSelectedPanel == null) changed = false; 218 if (selectedPanel.equals(childOrFacet.getId())) { 219 if (!(changed && phaseId == PhaseId.APPLY_REQUEST_VALUES)) { 220 applyPhase(context, childOrFacet, phaseId); 221 } 222 } 223 } 224 225 } 226 227 232 public void applyPhase(FacesContext context, UIComponent component, 233 PhaseId phaseId) { 234 if (phaseId == PhaseId.APPLY_REQUEST_VALUES) { 235 component.processDecodes(context); 236 } else if (phaseId == PhaseId.PROCESS_VALIDATIONS) { 237 component.processValidators(context); 238 } else if (phaseId == PhaseId.UPDATE_MODEL_VALUES) { 239 component.processUpdates(context); 240 } else { 241 throw new IllegalArgumentException (); 242 } 243 } 244 245 248 public void processDecodes(javax.faces.context.FacesContext context) { 249 250 if (context == null) { 251 throw new NullPointerException ("context"); 252 } 253 254 if (!isRendered()) { 255 return; 256 } 257 258 decode(context); 259 applyPhase(context, PhaseId.APPLY_REQUEST_VALUES); 260 } 261 262 265 public void processValidators(FacesContext context) { 266 267 if (context == null) { 268 throw new NullPointerException (); 269 } 270 if (!isRendered()) { 271 return; 272 } 273 applyPhase(context, PhaseId.PROCESS_VALIDATIONS); 274 } 275 276 277 280 public void processUpdates(FacesContext context) { 281 282 if (context == null) { 283 throw new NullPointerException (); 284 } 285 if (!isRendered()) { 286 return; 287 } 288 applyPhase(context, PhaseId.UPDATE_MODEL_VALUES); 289 } 290 291 } 292 | Popular Tags |