Author: abelevich
Date: 2010-06-24 08:06:26 -0400 (Thu, 24 Jun 2010)
New Revision: 17666
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SubTableRenderer.java
Log:
change getHiddenContainerStrategy method signature, refactoring
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-06-24
12:05:05 UTC (rev 17665)
+++
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-06-24
12:06:26 UTC (rev 17666)
@@ -125,7 +125,7 @@
}
return result;
}
-
+
public boolean getRendersChildren() {
return true;
}
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2010-06-24
12:05:05 UTC (rev 17665)
+++
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2010-06-24
12:06:26 UTC (rev 17666)
@@ -34,6 +34,7 @@
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.Row;
import org.richfaces.component.UIDataTableBase;
+import org.richfaces.component.util.HtmlUtil;
/**
* @author Anton Belevich
@@ -45,20 +46,9 @@
public static final String HIDDEN_CONTAINER_ID =":sc";
- public abstract EncodeStrategy getHiddenContainerStrategy();
+ public abstract EncodeStrategy getHiddenContainerStrategy(UIDataTableBase
dataTableBase);
- /**
- * Returns true if specified attribute (when present on the column) should generate
header even if it is not
- * specified on the table
- *
- * @param table
- * - rendered UIDataTable
- * @param attributeName
- * - attribute name
- * @return true if specified attribute should generate header on the table
- */
- // TODO nick - rename this method
- public boolean isHeaderFactoryColumnAttributePresent(UIDataTableBase table, String
attributeName) {
+ public boolean isColumnAttributeSet(UIDataTableBase table, String attributeName) {
Iterator<UIComponent> columns = table.columns();
boolean result = false;
while (columns.hasNext() && !result) {
@@ -111,11 +101,10 @@
super.encodeRows(facesContext, rowHolder);
}
- //TODO: anton -> refactor this
protected boolean isEncodeHeaders(UIDataTableBase table) {
- return table.isColumnFacetPresent("header") ||
isHeaderFactoryColumnAttributePresent(table, "sortBy")
- || isHeaderFactoryColumnAttributePresent(table, "comparator")
- || isHeaderFactoryColumnAttributePresent(table, "filterBy");
+ return table.isColumnFacetPresent("header") ||
isColumnAttributeSet(table, "sortBy")
+ || isColumnAttributeSet(table, "comparator")
+ || isColumnAttributeSet(table, "filterBy");
}
protected int getColumnsCount(UIDataTableBase table) {
@@ -200,32 +189,15 @@
if(encodePartialUpdate) {
String id = dataTableBase.getClientId(facesContext) + HIDDEN_CONTAINER_ID;
-
facesContext.getPartialViewContext().getPartialResponseWriter().startUpdate(id);
+ partialStart(facesContext, id);
}
encodeHiddens(writer, facesContext, dataTableBase, new
Object[]{encodeParentTBody});
if(encodePartialUpdate) {
- facesContext.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
- /*
- * DataTable
- * <tbody id="row">
- * </tbody>
- * <tbody id="hidden">
- * </tbody>
- *
- * SubTable
- * <tbody>
- * <tr id="row">
- * </tr
- * <tr id="hidden">
- * </tr
- * </tbody>
- *
- */
-
dataTableBase.setRowKey(facesContext, key);
dataTableBase.restoreOrigValue(facesContext);
}
@@ -244,13 +216,15 @@
}
protected void encodeHiddens(ResponseWriter writer, FacesContext facesContext,
UIDataTableBase dataTableBase, Object [] params) throws IOException {
- EncodeStrategy encodeStrategy = getHiddenContainerStrategy();
- encodeStrategy.begin(writer, facesContext, dataTableBase, params);
-
- encodeClientScript(writer, facesContext, dataTableBase);
- encodeHiddenInput(writer, facesContext, dataTableBase);
-
- encodeStrategy.end(writer, facesContext, dataTableBase, params);
+ EncodeStrategy encodeStrategy = getHiddenContainerStrategy(dataTableBase);
+ if(encodeStrategy != null) {
+ encodeStrategy.begin(writer, facesContext, dataTableBase, params);
+
+ encodeClientScript(writer, facesContext, dataTableBase);
+ encodeHiddenInput(writer, facesContext, dataTableBase);
+
+ encodeStrategy.end(writer, facesContext, dataTableBase, params);
+ }
}
public void encodeTableEnd(ResponseWriter writer) throws IOException {
@@ -276,7 +250,7 @@
writer.endElement(HTML.TBODY_ELEMENT);
}
- public void encodeFooterFacet(ResponseWriter writer, FacesContext context,
UIDataTableBase dataTable,
+ public void encodeFooterFacet(ResponseWriter writer, FacesContext facesContext,
UIDataTableBase dataTable,
boolean encodePartialUpdate) throws IOException {
UIComponent footer = dataTable.getFooter();
@@ -287,11 +261,11 @@
boolean encodeTfoot = containsThead();
if (encodeTfoot) {
- String footerClientId = dataTable.getClientId(context) +
":tf";
+ String footerClientId = dataTable.getClientId(facesContext) +
":tf";
if (encodePartialUpdate) {
partialUpdateEncoded = true;
-
context.getPartialViewContext().getPartialResponseWriter().startUpdate(footerClientId);
+ partialStart(facesContext, footerClientId);
}
writer.startElement(HTML.TFOOT_ELEMENT, dataTable);
@@ -300,7 +274,7 @@
}
int columns = getColumnsCount(dataTable);
- String id = dataTable.getClientId(context);
+ String id = dataTable.getClientId(facesContext);
boolean encodePartialUpdateForChildren = (encodePartialUpdate &&
!partialUpdateEncoded);
@@ -315,23 +289,23 @@
cellClass = mergeStyleClasses("columnFooterCellClass",
cellClass, dataTable);
firstClass = mergeStyleClasses("firstColumnFooterClass",
firstClass, dataTable);
- saveRowStyles(context,id, firstClass, rowClass, cellClass);
+ saveRowStyles(facesContext,id, firstClass, rowClass, cellClass);
String targetId = id + ":cf";
if (encodePartialUpdateForChildren) {
-
context.getPartialViewContext().getPartialResponseWriter().startUpdate(targetId);
+ partialStart(facesContext, targetId);
}
writer.startElement(HTML.TR_ELEMENT, dataTable);
writer.writeAttribute(HTML.ID_ATTRIBUTE, targetId, null);
- encodeStyleClass(writer, context, dataTable, null, rowClass);
- encodeColumnFacet(context, writer, dataTable, "footer",columns,
cellClass);
+ encodeStyleClass(writer, facesContext, dataTable, null, rowClass);
+ encodeColumnFacet(facesContext, writer, dataTable,
"footer",columns, cellClass);
writer.endElement(HTML.TR_ELEMENT);
if (encodePartialUpdateForChildren) {
-
context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
}
@@ -345,8 +319,8 @@
cellClass = mergeStyleClasses("footerCellClass", cellClass,
dataTable);
firstClass = mergeStyleClasses("footerFirstClass", firstClass,
dataTable);
// TODO nick - rename method "encodeTableHeaderFacet"
- saveRowStyles(context, id, firstClass, rowClass, cellClass);
- encodeTableFacet(context, writer, id, columns, footer,
"footer", rowClass, cellClass,
+ saveRowStyles(facesContext, id, firstClass, rowClass, cellClass);
+ encodeTableFacet(facesContext, writer, id, columns, footer,
"footer", rowClass, cellClass,
encodePartialUpdateForChildren);
}
@@ -354,30 +328,25 @@
writer.endElement(HTML.TFOOT_ELEMENT);
if (partialUpdateEncoded) {
-
context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
}
}
}
- //TODO nick - use org.richfaces.component.util.HtmlUtil.concatClasses(String...)
protected String mergeStyleClasses(String classAttribibute, String skinClass,
UIComponent component) {
- String styleClass = null;
String resultClass = skinClass;
-
+
+ String styleClass = null;
if(classAttribibute != null && component != null ) {
styleClass = (String)component.getAttributes().get(classAttribibute);
}
-
- if(styleClass != null && styleClass.trim().length() > 0) {
- resultClass = resultClass + " " + styleClass;
- }
-
- return resultClass;
+
+ return HtmlUtil.concatClasses(resultClass, styleClass);
}
- public void encodeHeaderFacet(ResponseWriter writer, FacesContext context,
UIDataTableBase dataTable,
+ public void encodeHeaderFacet(ResponseWriter writer, FacesContext facesContext,
UIDataTableBase dataTable,
boolean encodePartialUpdate) throws IOException {
UIComponent header = dataTable.getHeader();
@@ -389,11 +358,11 @@
boolean partialUpdateEncoded = false;
if (encodeThead) {
- String headerClientId = dataTable.getClientId(context) +
":th";
+ String headerClientId = dataTable.getClientId(facesContext) +
":th";
if (encodePartialUpdate) {
partialUpdateEncoded = true;
-
context.getPartialViewContext().getPartialResponseWriter().startUpdate(headerClientId);
+ partialStart(facesContext, headerClientId);
}
writer.startElement(HTML.THEAD_ELEMENT, dataTable);
@@ -402,7 +371,7 @@
}
int columns = getColumnsCount(dataTable);
- String id = dataTable.getClientId(context);
+ String id = dataTable.getClientId(facesContext);
boolean encodePartialUpdateForChildren = (encodePartialUpdate &&
!partialUpdateEncoded);
@@ -415,9 +384,9 @@
rowClass = mergeStyleClasses("headerClass", rowClass,
dataTable);
cellClass = mergeStyleClasses("headerCellClass", cellClass,
dataTable);
firstClass = mergeStyleClasses("headerFirstClass", firstClass,
dataTable);
- saveRowStyles(context, id, firstClass, rowClass, cellClass);
+ saveRowStyles(facesContext, id, firstClass, rowClass, cellClass);
- encodeTableFacet(context, writer, id, columns, header,
"header", rowClass, cellClass,
+ encodeTableFacet(facesContext, writer, id, columns, header,
"header", rowClass, cellClass,
encodePartialUpdateForChildren);
}
@@ -429,24 +398,24 @@
rowClass = mergeStyleClasses("columnHeaderClass", rowClass,
dataTable);
cellClass = mergeStyleClasses("columnHeaderCellClass",
cellClass, dataTable);
firstClass = mergeStyleClasses("columnHeaderFirstClass",
firstClass, dataTable);
- saveRowStyles(context, id, firstClass, rowClass, cellClass);
+ saveRowStyles(facesContext, id, firstClass, rowClass, cellClass);
String targetId = id + ":ch";
if (encodePartialUpdateForChildren) {
-
context.getPartialViewContext().getPartialResponseWriter().startUpdate(targetId);
+ partialStart(facesContext, targetId);
}
writer.startElement(HTML.TR_ELEMENT, dataTable);
writer.writeAttribute(HTML.ID_ATTRIBUTE, targetId, null);
- encodeStyleClass(writer, context, dataTable, null, rowClass);
+ encodeStyleClass(writer, facesContext, dataTable, null, rowClass);
- encodeColumnFacet(context, writer, dataTable, "header",
columns, cellClass);
+ encodeColumnFacet(facesContext, writer, dataTable, "header",
columns, cellClass);
writer.endElement(HTML.TR_ELEMENT);
if (encodePartialUpdateForChildren) {
-
context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
}
@@ -454,7 +423,7 @@
writer.endElement(HTML.THEAD_ELEMENT);
if (partialUpdateEncoded) {
-
context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
}
}
@@ -509,11 +478,11 @@
}
}
- protected void encodeTableFacet(FacesContext context, ResponseWriter writer, String
id, int columns,
+ protected void encodeTableFacet(FacesContext facesContext, ResponseWriter writer,
String id, int columns,
UIComponent footer, String facetName, String rowClass, String cellClass, boolean
encodePartialUpdate) throws IOException {
boolean isColumnGroup = (footer instanceof Row);
- String element = getCellElement(context, id);
+ String element = getCellElement(facesContext, id);
boolean partialUpdateEncoded = false;
@@ -522,17 +491,17 @@
if (encodePartialUpdate) {
partialUpdateEncoded = true;
-
context.getPartialViewContext().getPartialResponseWriter().startUpdate(targetId);
+ partialStart(facesContext, targetId);
}
writer.startElement(HTML.TR_ELEMENT, footer);
writer.writeAttribute(HTML.ID_ATTRIBUTE, targetId, null);
- encodeStyleClass(writer, context, footer, null, rowClass);
+ encodeStyleClass(writer, facesContext, footer, null, rowClass);
writer.startElement(element, footer);
- encodeStyleClass(writer, context, footer, null, cellClass);
+ encodeStyleClass(writer, facesContext, footer, null, cellClass);
if (columns > 0) {
writer.writeAttribute("colspan", String.valueOf(columns),
null);
@@ -542,13 +511,13 @@
}
if (encodePartialUpdate && !partialUpdateEncoded) {
-
context.getPartialViewContext().getPartialResponseWriter().startUpdate(footer.getClientId(context));
+ partialStart(facesContext, footer.getClientId(facesContext));
}
- footer.encodeAll(context);
+ footer.encodeAll(facesContext);
if (encodePartialUpdate && !partialUpdateEncoded) {
- context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
if (!isColumnGroup){
@@ -556,7 +525,7 @@
writer.endElement(HTML.TR_ELEMENT);
if (partialUpdateEncoded) {
- context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
}
}
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java 2010-06-24
12:05:05 UTC (rev 17665)
+++
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java 2010-06-24
12:06:26 UTC (rev 17666)
@@ -121,7 +121,7 @@
public void encodeBeforeRows(ResponseWriter writer, FacesContext
facesContext,UIDataTableBase dataTableBase, boolean encodeParentTBody, boolean
partialUpdate) throws IOException {
if(encodeParentTBody) {
if(partialUpdate) {
-
facesContext.getPartialViewContext().getPartialResponseWriter().startUpdate(dataTableBase.getClientId(facesContext)
+":tb");
+ partialStart(facesContext, dataTableBase.getClientId(facesContext)
+":tb");
}
encodeTableBodyStart(writer, facesContext, dataTableBase);
}
@@ -132,7 +132,7 @@
if(encodeParentTBody) {
encodeTableBodyEnd(writer);
if(partialUpdate) {
-
facesContext.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
}
}
@@ -402,7 +402,7 @@
put(context, component.getClientId(context), CELL_ELEMENT_KEY, HTML.TH_ELEM);
}
- public EncodeStrategy getHiddenContainerStrategy() {
+ public EncodeStrategy getHiddenContainerStrategy(UIDataTableBase dataTableBase) {
return new DataTableHiddenEncodeStrategy();
}
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SubTableRenderer.java
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SubTableRenderer.java 2010-06-24
12:05:05 UTC (rev 17665)
+++
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SubTableRenderer.java 2010-06-24
12:06:26 UTC (rev 17666)
@@ -169,29 +169,28 @@
writer.endElement(HTML.TR_ELEMENT);
}
- public void encodeRow(ResponseWriter writer, FacesContext context, RowHolderBase
holder) throws IOException {
+ public void encodeRow(ResponseWriter writer, FacesContext facesContext, RowHolderBase
holder) throws IOException {
RowHolder rowHolder = (RowHolder)holder;
Row row = rowHolder.getRow();
rowHolder.setRowStart(true);
Iterator<UIComponent> components = row.columns();
if (rowHolder.isUpdatePartial()) {
- context.getPartialViewContext().getPartialResponseWriter().startUpdate(
- ((UISubTable) row).getRelativeClientId(context) + ":b");
+ partialStart(facesContext,((UISubTable)
row).getRelativeClientId(facesContext) + ":b");
}
while (components.hasNext()) {
UIComponent component = components.next();
if(component instanceof UIColumn) {
- encodeColumn(context, writer, (UIColumn)component , rowHolder);
+ encodeColumn(facesContext, writer, (UIColumn)component , rowHolder);
} else if (component instanceof UISubTable) {
if(component.isRendered()) {
encodeRowEnd(writer);
}
- component.encodeAll(context);
+ component.encodeAll(facesContext);
rowHolder.setRowStart(true);
}
}
@@ -199,7 +198,7 @@
encodeRowEnd(writer);
if (rowHolder.isUpdatePartial()) {
- context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
}
@@ -219,25 +218,28 @@
return false;
}
- public void encodeHiddenInput(ResponseWriter writer, FacesContext facesContext,
UIDataTableBase dataTableBase) throws IOException {
- UISubTable subTable = (UISubTable)dataTableBase;
+ public void encodeHiddenInput(ResponseWriter writer, FacesContext facesContext,
UIDataTableBase dataTableBase)
+ throws IOException {
+ UISubTable subTable = (UISubTable) dataTableBase;
+
String stateId = subTable.getClientId(facesContext) + STATE;
writer.startElement(HTML.INPUT_ELEM, subTable);
- writer.writeAttribute(HTML.ID_ATTRIBUTE, stateId , null);
- writer.writeAttribute(HTML.NAME_ATTRIBUTE, stateId , null);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, stateId, null);
+ writer.writeAttribute(HTML.NAME_ATTRIBUTE, stateId, null);
writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
int state = subTable.isExpanded() ? 1 : 0;
writer.writeAttribute(HTML.VALUE_ATTRIBUTE, state, null);
writer.endElement(HTML.INPUT_ELEM);
-
+
String optionsId = subTable.getClientId(facesContext) + OPTIONS;
writer.startElement(HTML.INPUT_ELEM, subTable);
- writer.writeAttribute(HTML.ID_ATTRIBUTE, optionsId , null);
- writer.writeAttribute(HTML.NAME_ATTRIBUTE, optionsId , null);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, optionsId, null);
+ writer.writeAttribute(HTML.NAME_ATTRIBUTE, optionsId, null);
writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
writer.endElement(HTML.INPUT_ELEM);
+
}
public boolean containsThead() {
@@ -250,26 +252,28 @@
}
- public void encodeClientScript(ResponseWriter writer, FacesContext facesContext,
UIDataTableBase component) throws IOException {
- UISubTable subTable = (UISubTable)component;
+ public void encodeClientScript(ResponseWriter writer, FacesContext facesContext,
UIDataTableBase component)
+ throws IOException {
+ UISubTable subTable = (UISubTable) component;
+
String id = subTable.getClientId(facesContext);
UIComponent nestingForm = getUtils().getNestingForm(facesContext, subTable);
String formId = nestingForm != null ? nestingForm.getClientId(facesContext) :
"";
-
+
Map<String, Object> options = new HashMap<String, Object>();
- options.put("stateInput", subTable.getClientId(facesContext) +STATE);
- options.put("optionsInput", subTable.getClientId(facesContext)
+OPTIONS);
+ options.put("stateInput", subTable.getClientId(facesContext) + STATE);
+ options.put("optionsInput", subTable.getClientId(facesContext) +
OPTIONS);
options.put("expandMode", subTable.getExpandMode());
options.put("eventOptions",
AjaxRendererUtils.buildEventOptions(facesContext, subTable));
-
+
JSFunction jsFunction = new JSFunction("new RichFaces.ui.SubTable");
jsFunction.addParameter(id);
jsFunction.addParameter(formId);
jsFunction.addParameter(options);
writer.startElement(HTML.SCRIPT_ELEM, subTable);
- writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript",null);
+ writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
writer.writeText(jsFunction.toScript(), null);
writer.endElement(HTML.SCRIPT_ELEM);
}
@@ -366,15 +370,15 @@
UIDataTableBase dataTableBase = findParent(subTable);
String updateId = dataTableBase.getRelativeClientId(facesContext) +
":" + subTable.getId() +TB_ROW;
-
-
facesContext.getPartialViewContext().getPartialResponseWriter().startUpdate(updateId);
+
+ partialStart(facesContext, updateId);
encodeTableRows(writer, facesContext, subTable, false);
- facesContext.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ partialEnd(facesContext);
}
}
@Override
- public EncodeStrategy getHiddenContainerStrategy() {
+ public EncodeStrategy getHiddenContainerStrategy(UIDataTableBase dataTableBase) {
return new SubTableHiddenEncodeStrategy();
}