1 16 package org.apache.myfaces.custom.datalist; 17 18 import javax.faces.component.UIComponent; 19 import javax.faces.component.UIData; 20 import javax.faces.context.FacesContext; 21 import javax.faces.el.ValueBinding; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 29 public class HtmlDataList 30 extends UIData 31 { 32 33 public void processDecodes(FacesContext context) 34 { 35 int first = getFirst(); 36 int rows = getRows(); 37 int last; 38 if (rows == 0) 39 { 40 last = getRowCount(); 41 } 42 else 43 { 44 last = first + rows; 45 } 46 for (int rowIndex = first; rowIndex < last; rowIndex++) 47 { 48 setRowIndex(rowIndex); 49 if (isRowAvailable()) 50 { 51 for (Iterator it = getChildren().iterator(); it.hasNext();) 52 { 53 UIComponent child = (UIComponent)it.next(); 54 if (!child.isRendered()) 55 { 56 continue; 57 } 58 child.processDecodes(context); 59 } 60 } 61 } 62 63 setRowIndex(-1); 64 } 65 66 67 public void setRowIndex(int rowIndex) 68 { 69 super.setRowIndex(rowIndex); 70 String rowIndexVar = getRowIndexVar(); 71 String rowCountVar = getRowCountVar(); 72 if (rowIndexVar != null || rowCountVar != null) 73 { 74 Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap(); 75 if (rowIndex >= 0) 76 { 77 if (rowIndexVar != null) 79 { 80 requestMap.put(getRowIndexVar(), new Integer (rowIndex)); 81 } 82 if (rowCountVar != null) 83 { 84 requestMap.put(getRowCountVar(), new Integer (getRowCount())); 85 } 86 } 87 else 88 { 89 if (rowIndexVar != null) 91 { 92 requestMap.remove(getRowIndexVar()); 93 } 94 if (rowCountVar != null) 95 { 96 requestMap.remove(getRowCountVar()); 97 } 98 } 99 } 100 } 101 102 103 105 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlDataList"; 106 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.List"; 107 108 private String _layout = null; 109 private String _rowIndexVar = null; 110 private String _rowCountVar = null; 111 112 public HtmlDataList() 113 { 114 setRendererType(DEFAULT_RENDERER_TYPE); 115 } 116 117 118 public void setLayout(String layout) 119 { 120 _layout = layout; 121 } 122 123 public String getLayout() 124 { 125 if (_layout != null) return _layout; 126 ValueBinding vb = getValueBinding("layout"); 127 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 128 } 129 130 public void setRowIndexVar(String rowIndexVar) 131 { 132 _rowIndexVar = rowIndexVar; 133 } 134 135 public String getRowIndexVar() 136 { 137 if (_rowIndexVar != null) return _rowIndexVar; 138 ValueBinding vb = getValueBinding("rowIndexVar"); 139 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 140 } 141 142 public void setRowCountVar(String rowCountVar) 143 { 144 _rowCountVar = rowCountVar; 145 } 146 147 public String getRowCountVar() 148 { 149 if (_rowCountVar != null) return _rowCountVar; 150 ValueBinding vb = getValueBinding("rowCountVar"); 151 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 152 } 153 154 155 public Object saveState(FacesContext context) 156 { 157 Object values[] = new Object [4]; 158 values[0] = super.saveState(context); 159 values[1] = _layout; 160 values[2] = _rowIndexVar; 161 values[3] = _rowCountVar; 162 return ((Object ) (values)); 163 } 164 165 public void restoreState(FacesContext context, Object state) 166 { 167 Object values[] = (Object [])state; 168 super.restoreState(context, values[0]); 169 _layout = (String )values[1]; 170 _rowIndexVar = (String )values[2]; 171 _rowCountVar = (String )values[3]; 172 } 173 } 175 | Popular Tags |