1 33 34 package com.icesoft.faces.component.ext; 35 36 import com.icesoft.faces.component.panelseries.UISeries; 37 38 import javax.faces.component.NamingContainer; 39 import javax.faces.component.UIComponent; 40 import javax.faces.context.FacesContext; 41 import javax.faces.el.ValueBinding; 42 import javax.faces.event.PhaseId; 43 import java.util.HashMap ; 44 import java.util.Iterator ; 45 46 47 public class UIColumns extends UISeries { 48 public static final String COMPONENT_TYPE = "com.icesoft.faces.Columns"; 49 public static final String COMPONENT_FAMILY = "javax.faces.Columns"; 50 51 public String getFamily() { 52 return (COMPONENT_FAMILY); 53 } 54 55 public UIColumns() { 56 setRendererType(null); 57 } 58 59 60 63 private boolean rendered = true; 64 private boolean renderedSet = false; 65 66 public boolean isRendered() { 67 if (renderedSet) { 68 return (rendered); 69 } 70 ValueBinding vb = getValueBinding("rendered"); 71 if (vb != null) { 72 return (!Boolean.FALSE.equals(vb.getValue(getFacesContext()))); 73 } else { 74 return (this.rendered); 75 } 76 77 } 78 79 80 public void setRendered(boolean rendered) { 81 this.rendered = rendered; 82 this.renderedSet = true; 83 } 84 85 protected void iterate(FacesContext facesContext, PhaseId phase) { 86 if (isHeaderFacet() && (UIComponent) getFacets().get("header")!= null) { 88 setRowIndex(-1); 90 UIComponent facet = (UIComponent) getFacets().get("header"); 91 int rowsProcessed = 0; 92 int currentRowIndex = getFirst() - 1; 93 int displayedRows = getRows(); 94 while (1 == 1) { 96 if ((displayedRows > 0) && (++rowsProcessed > displayedRows)) { 98 break; 99 } 100 setRowIndex(++currentRowIndex); 102 if (!isRowAvailable()) { 104 break; 105 } 106 Iterator kids = facet.getChildren().iterator(); 107 while (kids.hasNext()) { 108 UIComponent kid = (UIComponent) kids.next(); 109 processKids(facesContext, phase, kid); 110 } 111 } 112 } else { 113 setRowIndex(-1); 115 int rowsProcessed = 0; 116 int currentRowIndex = getFirst() - 1; 117 int displayedRows = getRows(); 118 while (1 == 1) { 120 if ((displayedRows > 0) && (++rowsProcessed > displayedRows)) { 122 break; 123 } 124 setRowIndex(++currentRowIndex); 126 if (!isRowAvailable()) { 128 break; 129 } 130 Iterator kids = getChildren().iterator(); 131 while (kids.hasNext()) { 132 UIComponent kid = (UIComponent) kids.next(); 133 processKids(facesContext, phase, kid); 134 } 135 } 136 setRowIndex(-1); 138 } 139 } 140 141 public String getId() { 142 return String.valueOf(getRowIndex()) + getRowId(); 143 } 144 145 public void processKids(FacesContext context, PhaseId phaseId, 146 UIComponent kid) { 147 if (phaseId == PhaseId.APPLY_REQUEST_VALUES) { 148 kid.processDecodes(context); 149 } else if (phaseId == PhaseId.PROCESS_VALIDATIONS) { 150 kid.processValidators(context); 151 } else if (phaseId == PhaseId.UPDATE_MODEL_VALUES) { 152 kid.processUpdates(context); 153 } else { 154 throw new IllegalArgumentException (); 155 } 156 } 157 158 159 protected void restoreChildrenState(FacesContext facesContext) { 160 Iterator children = null; 161 if (isHeaderFacet()) { 162 children = getFacets().values().iterator(); 163 } else { 164 if (getRowIndex() < 0) { 165 return; 166 } else { 167 children = getChildren().iterator(); 168 } 169 } 170 while (children.hasNext()) { 171 UIComponent child = (UIComponent) children.next(); 172 restoreChildState(facesContext, child); 173 } 174 } 175 176 180 protected void saveChildrenState(FacesContext facesContext) { 181 Iterator children = null; 182 if (isHeaderFacet()) { 183 children = getFacets().values().iterator(); 184 } else { 185 if (getRowIndex() < 0) { 186 return; 187 } else { 188 children = getChildren().iterator(); 189 } 190 } 191 while (children.hasNext()) { 192 UIComponent child = (UIComponent) children.next(); 193 saveChildState(facesContext, child); 194 } 195 } 196 197 public int getRowId() { 198 if (getParent() != null && 199 ((HtmlDataTable) getParent()).getRowIndex() >= 0) { 200 return ((HtmlDataTable) getParent()).getRowIndex(); 201 } else { 202 return 0; 203 } 204 } 205 206 public String getClientId(FacesContext context) { 207 if (context == null) { 208 throw new NullPointerException (); 209 } 210 String baseClientId = super.getClientId(context); 211 if (getRowIndex() >= 0) { 212 return (baseClientId + NamingContainer.SEPARATOR_CHAR + 213 getRowIndex() + getRowId()); 214 } else { 215 return (baseClientId); 216 } 217 218 } 219 220 public boolean isHeaderFacet() { 221 return (((HtmlDataTable) getParent()).getRowIndex() < 0) ? true : false; 222 } 223 224 public void processDecodes(FacesContext context) { 225 226 if (context == null) { 227 throw new NullPointerException (); 228 } 229 if (!isRendered()) { 230 return; 231 } 232 233 dataModel = null; if (null == savedChildren) { 235 savedChildren = new HashMap (); 236 } 237 iterate(context, PhaseId.APPLY_REQUEST_VALUES); 238 decode(context); 239 } 240 } | Popular Tags |