You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mk...@apache.org on 2006/05/17 18:01:11 UTC
svn commit: r407293 -
/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java
Author: mkienenb
Date: Wed May 17 09:01:11 2006
New Revision: 407293
URL: http://svn.apache.org/viewvc?rev=407293&view=rev
Log:
Fix for TOMAHAWK-5 -- Merge newspaperTable into t:dataTable.
Modified:
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java
Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java?rev=407293&r1=407292&r2=407293&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java Wed May 17 09:01:11 2006
@@ -15,14 +15,10 @@
*/
package org.apache.myfaces.shared.renderkit.html;
-import org.apache.myfaces.shared.renderkit.JSFAttr;
-import org.apache.myfaces.shared.renderkit.RendererUtils;
-import org.apache.myfaces.shared.renderkit.html.HTML;
-import org.apache.myfaces.shared.renderkit.html.HtmlRenderer;
-import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
@@ -30,10 +26,13 @@
import javax.faces.component.html.HtmlDataTable;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.shared.renderkit.JSFAttr;
+import org.apache.myfaces.shared.renderkit.RendererUtils;
+import org.apache.myfaces.shared.util.ArrayUtils;
+import org.apache.myfaces.shared.util.StringUtils;
/**
* Common methods for renderers for components that subclass the standard
@@ -54,6 +53,30 @@
private static final Log log = LogFactory.getLog(HtmlTableRendererBase.class);
/**
+ * @param component dataTable
+ * @return number of layout columns
+ */
+ protected int getNewspaperColumns(UIComponent component) {
+ return 1;
+ }
+
+ /**
+ * @param component dataTable
+ * @return component to display between layout columns
+ */
+ protected UIComponent getNewspaperTableSpacer(UIComponent component) {
+ return null;
+ }
+
+ /**
+ * @param component dataTable
+ * @return whether dataTable has component to display between layout columns
+ */
+ protected boolean hasNewspaperTableSpacer(UIComponent component) {
+ return false;
+ }
+
+ /**
* @see javax.faces.render.Renderer#getRendersChildren()
*/
public boolean getRendersChildren()
@@ -105,6 +128,64 @@
}
/**
+ * Gets styles for the specified component.
+ */
+ protected static Styles getStyles(UIData uiData) {
+ String rowClasses;
+ String columnClasses;
+ if(uiData instanceof HtmlDataTable) {
+ rowClasses = ((HtmlDataTable)uiData).getRowClasses();
+ columnClasses = ((HtmlDataTable)uiData).getColumnClasses();
+ } else {
+ rowClasses = (String)uiData.getAttributes().get(JSFAttr.ROW_CLASSES_ATTR);
+ columnClasses = (String)uiData.getAttributes().get(JSFAttr.COLUMN_CLASSES_ATTR);
+ }
+ return new Styles(rowClasses, columnClasses);
+ }
+
+ /**
+ * Class manages the styles from String lists.
+ */
+ protected static class Styles {
+
+ private String[] _columnStyle;
+ private String[] _rowStyle;
+
+ Styles(String rowStyles, String columnStyles) {
+ _rowStyle = (rowStyles == null)
+ ? ArrayUtils.EMPTY_STRING_ARRAY
+ : StringUtils.trim(
+ StringUtils.splitShortString(rowStyles, ','));
+ _columnStyle = (columnStyles == null)
+ ? ArrayUtils.EMPTY_STRING_ARRAY
+ : StringUtils.trim(
+ StringUtils.splitShortString(columnStyles, ','));
+ }
+
+ public String getRowStyle(int idx) {
+ if(!hasRowStyle()) {
+ return null;
+ }
+ return _rowStyle[idx % _rowStyle.length];
+ }
+
+ public String getColumnStyle(int idx) {
+ if(!hasColumnStyle()) {
+ return null;
+ }
+ return _columnStyle[idx % _columnStyle.length];
+ }
+
+ public boolean hasRowStyle() {
+ return _rowStyle.length > 0;
+ }
+
+ public boolean hasColumnStyle() {
+ return _columnStyle.length > 0;
+ }
+ }
+
+ /**
* Renders everything inside the TBODY tag by iterating over the row objects
* between offsets first and first+rows and applying the UIColumn components
* to those objects.
@@ -117,20 +198,9 @@
UIData uiData = (UIData) component;
ResponseWriter writer = facesContext.getResponseWriter();
- String rowClasses;
- String columnClasses;
- if (component instanceof HtmlDataTable)
- {
- rowClasses = ((HtmlDataTable) component).getRowClasses();
- columnClasses = ((HtmlDataTable) component).getColumnClasses();
- }
- else
- {
- rowClasses = (String) component.getAttributes().get(org.apache.myfaces.shared.renderkit.JSFAttr.ROW_CLASSES_ATTR);
- columnClasses = (String) component.getAttributes().get(JSFAttr.COLUMN_CLASSES_ATTR);
- }
- Iterator rowStyleIterator = new StyleIterator(rowClasses);
- StyleIterator columnStyleIterator = new StyleIterator(columnClasses);
+ // begin the table
+ // get the CSS styles
+ Styles styles = getStyles(uiData);
int first = uiData.getFirst();
int rows = uiData.getRows();
@@ -143,36 +213,59 @@
{
last = first + rows;
}
- for (int rowIndex = first; last==-1 || rowIndex < last; rowIndex++)
- {
- uiData.setRowIndex(rowIndex);
-
- //scrolled past the last row
- if (!uiData.isRowAvailable())
- break;
- columnStyleIterator.reset();
+ int newspaperColumns = getNewspaperColumns(component);
+ int newspaperRows;
+ if((last - first) % newspaperColumns == 0)
+ newspaperRows = (last - first) / newspaperColumns;
+ else newspaperRows = ((last - first) / newspaperColumns) + 1;
+ // walk through the newspaper rows
+ for(int nr = 0; nr < newspaperRows; nr++)
+ {
beforeRow(facesContext, uiData);
HtmlRendererUtils.writePrettyLineSeparator(facesContext);
- renderRowStart(facesContext, writer, uiData, rowStyleIterator);
+ renderRowStart(facesContext, writer, uiData, styles, nr);
- List children = getChildren(component);
- for (int j = 0, size = getChildCount(component); j < size; j++)
- {
- UIComponent child = (UIComponent) children.get(j);
- if (child.isRendered())
+ // walk through the newspaper columns
+ for(int nc = 0; nc < newspaperColumns; nc++) {
+
+ // the current row in the 'real' table
+ int currentRow = nc * newspaperRows + nr + first;
+
+ // if this row is not to be rendered
+ if(currentRow >= last) continue;
+
+ // bail if any row does not exist
+ uiData.setRowIndex(currentRow);
+ if(!uiData.isRowAvailable()) {
+ log.error("Row is not available. Rowindex = " + currentRow);
+ return;
+ }
+
+ List children = getChildren(component);
+ for (int j = 0, size = getChildCount(component); j < size; j++)
{
- boolean columnRendering = child instanceof UIColumn;
-
- if (columnRendering)
- beforeColumn(facesContext, uiData, j);
+ UIComponent child = (UIComponent) children.get(j);
+ if (child.isRendered())
+ {
+ boolean columnRendering = child instanceof UIColumn;
+
+ if (columnRendering)
+ beforeColumn(facesContext, uiData, j);
+
+ encodeColumnChild(facesContext, writer, uiData, child, styles, nc * uiData.getChildCount() + j);
- encodeColumnChild(facesContext, writer, uiData, child, columnStyleIterator);
-
- if (columnRendering)
- afterColumn(facesContext, uiData, j);
+ if (columnRendering)
+ afterColumn(facesContext, uiData, j);
+ }
+ }
+
+ if (hasNewspaperTableSpacer(uiData))
+ {
+ // draw the spacer facet
+ if(nc < newspaperColumns - 1) renderSpacerCell(facesContext, writer, uiData);
}
}
renderRowEnd(facesContext, writer, uiData);
@@ -182,11 +275,11 @@
}
protected void encodeColumnChild(FacesContext facesContext, ResponseWriter writer,
- UIData uiData, UIComponent component, Iterator columnStyleIterator) throws IOException
+ UIData uiData, UIComponent component, Styles styles, int columnStyleIndex) throws IOException
{
if (component instanceof UIColumn)
{
- renderColumnBody(facesContext, writer, uiData, component, columnStyleIterator);
+ renderColumnBody(facesContext, writer, uiData, component, styles, columnStyleIndex);
}
}
@@ -209,12 +302,12 @@
ResponseWriter writer,
UIData uiData,
UIComponent component,
- Iterator columnStyleIterator) throws IOException
+ Styles styles, int columnStyleIndex) throws IOException
{
writer.startElement(HTML.TD_ELEM, uiData);
- if (columnStyleIterator.hasNext())
+ if (styles.hasColumnStyle())
{
- writer.writeAttribute(HTML.CLASS_ATTR, columnStyleIterator.next(), null);
+ writer.writeAttribute(HTML.CLASS_ATTR, styles.getColumnStyle(columnStyleIndex), null);
}
RendererUtils.renderChild(facesContext, component);
@@ -233,11 +326,11 @@
FacesContext facesContext,
ResponseWriter writer,
UIData uiData,
- Iterator rowStyleIterator) throws IOException
+ Styles styles, int rowStyleIndex) throws IOException
{
writer.startElement(HTML.TR_ELEM, uiData);
- renderRowStyle(facesContext, writer, uiData, rowStyleIterator);
+ renderRowStyle(facesContext, writer, uiData, styles, rowStyleIndex);
Object rowId = uiData.getAttributes().get(org.apache.myfaces.shared.renderkit.JSFAttr.ROW_ID);
@@ -247,12 +340,12 @@
}
}
- protected void renderRowStyle(FacesContext facesContext, ResponseWriter writer, UIData uiData, Iterator rowStyleIterator) throws IOException
+ protected void renderRowStyle(FacesContext facesContext, ResponseWriter writer, UIData uiData, Styles styles, int rowStyleIndex) throws IOException
{
- if (rowStyleIterator.hasNext())
- {
- writer.writeAttribute(HTML.CLASS_ATTR, rowStyleIterator.next(), null);
- }
+ if(styles.hasRowStyle()) {
+ String rowStyle = styles.getRowStyle(rowStyleIndex);
+ writer.writeAttribute(HTML.CLASS_ATTR, rowStyle, null);
+ }
}
/**
@@ -581,7 +674,15 @@
{
writer.writeAttribute(HTML.SCOPE_ATTR, HTML.SCOPE_COLGROUP_VALUE, null);
}
- writer.writeAttribute(HTML.COLSPAN_ATTR, new Integer(colspan), null);
+
+ // span all the table's columns
+ int newsPaperColumns = getNewspaperColumns(component);
+ int totalColumns = colspan * newsPaperColumns;
+ if(hasNewspaperTableSpacer(component))
+ {
+ totalColumns = totalColumns + newsPaperColumns - 1;
+ }
+ writer.writeAttribute(HTML.COLSPAN_ATTR, new Integer(totalColumns), null);
if (styleClass != null)
{
writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
@@ -604,23 +705,45 @@
writer.startElement(HTML.TR_ELEM, component);
int columnIndex = 0;
- for (Iterator it = getChildren(component).iterator(); it.hasNext();)
+ int newspaperColumns = getNewspaperColumns(component);
+ for(int nc = 0; nc < newspaperColumns; nc++)
{
- UIComponent uiComponent = (UIComponent) it.next();
- if (uiComponent.isRendered())
+ for (Iterator it = getChildren(component).iterator(); it.hasNext();)
{
- if (component instanceof UIData && uiComponent instanceof UIColumn)
- beforeColumnHeaderOrFooter(facesContext, (UIData)component, header, columnIndex);
-
- renderColumnChildHeaderOrFooterRow(facesContext, writer, uiComponent, styleClass, header);
+ UIComponent uiComponent = (UIComponent) it.next();
+ if (uiComponent.isRendered())
+ {
+ if (component instanceof UIData && uiComponent instanceof UIColumn)
+ beforeColumnHeaderOrFooter(facesContext, (UIData)component, header, columnIndex);
- if (component instanceof UIData && uiComponent instanceof UIColumn)
- afterColumnHeaderOrFooter(facesContext, (UIData)component, header, columnIndex);
+ renderColumnChildHeaderOrFooterRow(facesContext, writer, uiComponent, styleClass, header);
+
+ if (component instanceof UIData && uiComponent instanceof UIColumn)
+ afterColumnHeaderOrFooter(facesContext, (UIData)component, header, columnIndex);
+ }
+ columnIndex += 1;
+ }
+ writer.endElement(HTML.TR_ELEM);
+
+ if (hasNewspaperTableSpacer(component))
+ {
+ // draw the spacer facet
+ if(nc < newspaperColumns - 1) renderSpacerCell(facesContext, writer, component);
}
- columnIndex += 1;
}
- writer.endElement(HTML.TR_ELEM);
}
+
+ /**
+ * Renders a spacer between adjacent newspaper columns.
+ */
+ protected void renderSpacerCell(FacesContext facesContext, ResponseWriter writer, UIComponent component) throws IOException {
+ UIComponent spacer = getNewspaperTableSpacer(component);
+ if(spacer == null) return;
+
+ writer.startElement(HTML.TD_ELEM, component);
+ RendererUtils.renderChild(facesContext, spacer);
+ writer.endElement(HTML.TD_ELEM);
+ }
protected void renderColumnChildHeaderOrFooterRow(FacesContext facesContext,
ResponseWriter writer, UIComponent uiComponent, String styleClass, boolean header) throws IOException