1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.renderkit.html.ext;
20
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.logging.Logger;
24
25 import javax.faces.component.UIColumn;
26 import javax.faces.component.UIComponent;
27 import javax.faces.component.UIData;
28 import javax.faces.context.FacesContext;
29 import javax.faces.context.ResponseWriter;
30 import javax.faces.convert.ConverterException;
31
32 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
33 import org.apache.myfaces.component.html.ext.HtmlDataTable;
34 import org.apache.myfaces.component.html.ext.HtmlTableRow;
35 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
36 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
37 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
38 import org.apache.myfaces.shared_tomahawk.util.ArrayUtils;
39 import org.apache.myfaces.shared_tomahawk.util.StringUtils;
40
41 @JSFRenderer(renderKitId = "HTML_BASIC", family = "org.apache.myfaces.HtmlTableRow", type = "org.apache.myfaces.HtmlTableRow")
42 public class HtmlTableRowRenderer extends HtmlTableRenderer
43 {
44 private static final Logger log = Logger.getLogger(HtmlTableRowRenderer.class.getName());
45
46 private static final Integer[] ZERO_INT_ARRAY = new Integer[]{0};
47
48 @Override
49 public void encodeEnd(FacesContext facesContext, UIComponent component)
50 throws IOException
51 {
52
53 RendererUtils.checkParamValidity(facesContext, component, HtmlTableRow.class);
54
55 ResponseWriter writer = facesContext.getResponseWriter();
56 UIData uiData = (UIData) component.getParent();
57
58 if (uiData instanceof HtmlDataTable)
59 {
60 HtmlDataTable htmlDataTable = (HtmlDataTable) uiData;
61
62 int rowCount = uiData.getRowCount();
63
64
65
66 Styles styles = getStyles(uiData);
67
68 int first = uiData.getFirst();
69 int rows = uiData.getRows();
70 int last;
71
72 if (rows <= 0)
73 {
74 last = rowCount;
75 }
76 else
77 {
78 last = first + rows;
79 if (last > rowCount)
80 {
81 last = rowCount;
82 }
83 }
84
85 int newspaperColumns = getNewspaperColumns(uiData);
86 int newspaperRows;
87 if((last - first) % newspaperColumns == 0)
88 newspaperRows = (last - first) / newspaperColumns;
89 else newspaperRows = ((last - first) / newspaperColumns) + 1;
90 boolean newspaperHorizontalOrientation = isNewspaperHorizontalOrientation(uiData);
91
92
93 Integer[] bodyrows = null;
94 String bodyrowsAttr = (String) uiData.getAttributes().get(JSFAttr.BODYROWS_ATTR);
95 if(bodyrowsAttr != null && !"".equals(bodyrowsAttr))
96 {
97 String[] bodyrowsString = StringUtils.trim(StringUtils.splitShortString(bodyrowsAttr, ','));
98
99
100 bodyrows = new Integer[bodyrowsString.length];
101 for(int i = 0; i < bodyrowsString.length; i++)
102 {
103 bodyrows[i] = new Integer(bodyrowsString[i]);
104 }
105
106 }
107 else
108 {
109 bodyrows = ZERO_INT_ARRAY;
110 }
111
112
113 int savedRow = uiData.getRowIndex();
114
115
116
117 int nr = newspaperHorizontalOrientation ?
118 (savedRow-first)/newspaperColumns :
119 savedRow-first;
120
121
122
123
124 boolean rowStartRendered = false;
125
126 for(int nc = 0; nc < newspaperColumns; nc++) {
127
128
129 int currentRow;
130 if (newspaperHorizontalOrientation)
131 currentRow = nr * newspaperColumns + nc + first;
132 else
133 currentRow = nc * newspaperRows + nr + first;
134
135
136 if(currentRow >= last) continue;
137
138
139 uiData.setRowIndex(currentRow);
140 if(!uiData.isRowAvailable()) {
141 log.severe("Row is not available. Rowindex = " + currentRow);
142 break;
143 }
144
145 if (nc == 0) {
146
147
148
149
150 if(ArrayUtils.contains(bodyrows, currentRow))
151 {
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 }
167
168 HtmlRendererUtils.writePrettyLineSeparator(facesContext);
169 renderRowStart(facesContext, writer, uiData, styles, nr);
170 rowStartRendered = true;
171 }
172
173 List children = getChildren(uiData);
174 for (int j = 0, size = getChildCount(uiData); j < size; j++)
175 {
176 UIComponent child = (UIComponent) children.get(j);
177 if (child.isRendered())
178 {
179 boolean columnRendering = child instanceof UIColumn;
180
181 if (columnRendering)
182 beforeColumn(facesContext, uiData, j);
183
184 encodeColumnChild(facesContext, writer, uiData, child, styles, nc * uiData.getChildCount() + j);
185
186 if (columnRendering)
187 afterColumn(facesContext, uiData, j);
188 }
189 }
190
191 if (hasNewspaperTableSpacer(uiData))
192 {
193
194 if(nc < newspaperColumns - 1) renderSpacerCell(facesContext, writer, uiData);
195 }
196 }
197 if (rowStartRendered)
198 {
199 renderRowEnd(facesContext, writer, uiData);
200
201 }
202
203
204 if (uiData.getRowIndex() != savedRow)
205 {
206 uiData.setRowIndex(savedRow);
207 }
208 }
209 }
210
211 @Override
212 public boolean getRendersChildren()
213 {
214 return true;
215 }
216
217 public void encodeChildren(FacesContext context, UIComponent component) throws IOException
218 {
219 }
220
221 public void decode(FacesContext context, UIComponent component)
222 {
223 if (context == null)
224 throw new NullPointerException("context");
225 if (component == null)
226 throw new NullPointerException("component");
227 }
228
229 public void encodeBegin(FacesContext context, UIComponent component) throws IOException
230 {
231 if (context == null)
232 throw new NullPointerException("context");
233 if (component == null)
234 throw new NullPointerException("component");
235 }
236
237 public String convertClientId(FacesContext context, String clientId)
238 {
239 if (context == null)
240 throw new NullPointerException("context");
241 if (clientId == null)
242 throw new NullPointerException("clientId");
243 return clientId;
244 }
245
246 public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
247 throws ConverterException
248 {
249 if (context == null)
250 throw new NullPointerException("context");
251 if (component == null)
252 throw new NullPointerException("component");
253 return submittedValue;
254 }
255 }