Author: nbelaevski
Date: 2010-05-18 20:40:31 -0400 (Tue, 18 May 2010)
New Revision: 17114
Modified:
root/ui-sandbox/tables/trunk/ui/src/main/java/org/richfaces/component/UIExtendedDataTable.java
root/ui-sandbox/tables/trunk/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
Log:
https://jira.jboss.org/browse/RF-7856
https://jira.jboss.org/browse/RF-8630
Modified:
root/ui-sandbox/tables/trunk/ui/src/main/java/org/richfaces/component/UIExtendedDataTable.java
===================================================================
---
root/ui-sandbox/tables/trunk/ui/src/main/java/org/richfaces/component/UIExtendedDataTable.java 2010-05-19
00:33:46 UTC (rev 17113)
+++
root/ui-sandbox/tables/trunk/ui/src/main/java/org/richfaces/component/UIExtendedDataTable.java 2010-05-19
00:40:31 UTC (rev 17114)
@@ -33,7 +33,6 @@
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
-import javax.faces.render.Renderer;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.Range;
@@ -48,7 +47,7 @@
* @author Anton Belevich
*
*/
-public class UIExtendedDataTable extends UIDataTableBase implements MetaComponentResolver
{
+public class UIExtendedDataTable extends UIDataTableBase implements
MetaComponentResolver, MetaComponentEncoder {
public static final String SCROLL = "scroll";
public static final String HEADER = "header";
@@ -69,50 +68,6 @@
SUPPORTED_META_COMPONENTS.add(BODY);
}
- private final class MetaComponentRenderVisitCallback implements VisitCallback {
-
- private VisitCallback delegateCallback;
-
- public MetaComponentRenderVisitCallback(VisitCallback delegateCallback) {
- super();
- this.delegateCallback = delegateCallback;
- }
-
- public VisitResult visit(VisitContext visitContext, UIComponent target) {
- if (UIExtendedDataTable.this.equals(target)) {
- FacesContext context = visitContext.getFacesContext();
- String metaComponentId = (String)
context.getAttributes().get(ExtendedVisitContext.META_COMPONENT_ID);
- if (SUPPORTED_META_COMPONENTS.contains(metaComponentId)) {
-
- if (SCROLL.equals(metaComponentId)) {
- Map<String, Object> attributes = getAttributes();
- Integer submittedClientFirst = (Integer)
attributes.remove(SUBMITTED_CLIENT_FIRST);
- if (submittedClientFirst != null) {
- attributes.put(OLD_CLIENT_FIRST, getClientFirst());
- setClientFirst(submittedClientFirst);
- }
- }
-
- Renderer renderer = getRenderer(context);
- try {
- ((MetaComponentRenderer) renderer).encodeMetaComponent(context,
target, metaComponentId);
- } catch (IOException e) {
- if (RENDERKIT_LOG.isErrorEnabled()) {
- RENDERKIT_LOG.error(e.getMessage());
- }
- if (RENDERKIT_LOG.isDebugEnabled()) {
- RENDERKIT_LOG.debug(e.getMessage(), e);
- }
- }
-
- return VisitResult.REJECT;
- }
- }
-
- return delegateCallback.visit(visitContext, target);
- }
- }
-
protected enum PropertyKeys {
clientFirst, clientRows
}
@@ -136,6 +91,23 @@
return null;
}
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
+ if (SUPPORTED_META_COMPONENTS.contains(metaComponentId)) {
+
+ if (SCROLL.equals(metaComponentId)) {
+ Map<String, Object> attributes = getAttributes();
+ Integer submittedClientFirst = (Integer)
attributes.remove(SUBMITTED_CLIENT_FIRST);
+ if (submittedClientFirst != null) {
+ attributes.put(OLD_CLIENT_FIRST, getClientFirst());
+ setClientFirst(submittedClientFirst);
+ }
+ }
+
+ MetaComponentRenderer renderer = (MetaComponentRenderer)
getRenderer(context);
+ renderer.encodeMetaComponent(context, this, metaComponentId);
+ }
+ }
+
/* (non-Javadoc)
* @see
org.richfaces.component.UIDataAdaptor#visitFixedChildren(javax.faces.component.visit.VisitContext,
javax.faces.component.visit.VisitCallback, boolean)
*/
@@ -146,11 +118,9 @@
if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER)
{
//TODO nick - call preEncodeBegin(...) and emit PreRenderEvent
- MetaComponentRenderVisitCallback rendererCallback = new
MetaComponentRenderVisitCallback(callback);
-
VisitResult visitResult;
- visitResult = extendedVisitContext.invokeMetaComponentVisitCallback(this,
rendererCallback, HEADER);
+ visitResult = extendedVisitContext.invokeMetaComponentVisitCallback(this,
callback, HEADER);
if (visitResult == VisitResult.ACCEPT) {
//TODO nick - visit header?
@@ -158,7 +128,7 @@
return true;
}
- visitResult = extendedVisitContext.invokeMetaComponentVisitCallback(this,
rendererCallback, FOOTER);
+ visitResult = extendedVisitContext.invokeMetaComponentVisitCallback(this,
callback, FOOTER);
if (visitResult == VisitResult.ACCEPT) {
//TODO nick - visit footer?
@@ -176,21 +146,17 @@
}
@Override
- protected boolean visitDataChildren(VisitContext visitContext, final VisitCallback
callback, boolean resetKeyBeforeVisit) {
- if (visitContext instanceof ExtendedVisitContext) {
+ protected boolean visitDataChildren(VisitContext visitContext, final VisitCallback
callback, boolean visitRows) {
+ if (visitContext instanceof ExtendedVisitContext && visitRows) {
ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext)
visitContext;
if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER)
{
//TODO nick - call preEncodeBegin(...) and emit PreRenderEvent
- if (resetKeyBeforeVisit) {
- setRowKey(visitContext.getFacesContext(), null);
- }
+ setRowKey(visitContext.getFacesContext(), null);
- MetaComponentRenderVisitCallback rendererCallback = new
MetaComponentRenderVisitCallback(callback);
-
VisitResult result;
- result = extendedVisitContext.invokeMetaComponentVisitCallback(this,
rendererCallback, SCROLL);
+ result = extendedVisitContext.invokeMetaComponentVisitCallback(this,
callback, SCROLL);
if (result == VisitResult.ACCEPT) {
//TODO nick - visit scroll?
@@ -200,7 +166,7 @@
//TODO nick - scroll vs body?
- result = extendedVisitContext.invokeMetaComponentVisitCallback(this,
rendererCallback, BODY);
+ result = extendedVisitContext.invokeMetaComponentVisitCallback(this,
callback, BODY);
if (result == VisitResult.ACCEPT) {
//TODO nick - visit body?
@@ -214,7 +180,7 @@
}
}
- return super.visitDataChildren(visitContext, callback, resetKeyBeforeVisit);
+ return super.visitDataChildren(visitContext, callback, visitRows);
}
/**
Modified:
root/ui-sandbox/tables/trunk/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
===================================================================
---
root/ui-sandbox/tables/trunk/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-05-19
00:33:46 UTC (rev 17113)
+++
root/ui-sandbox/tables/trunk/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-05-19
00:40:31 UTC (rev 17114)
@@ -90,8 +90,6 @@
private Part current;
private Iterator<Part> partIterator;
-
-
public RendererState(FacesContext context, UIDataTableBase table) {
super(context);
this.table = table;
@@ -152,6 +150,306 @@
}
+ private class BaseTableEncoderStrategy {
+
+ void encodeStartUpdate(FacesContext context, String targetId) throws IOException
{
+
+ }
+
+ void encodeEndUpdate(FacesContext context) throws IOException {
+
+ }
+
+ private void encodeHeaderOrFooterCell(FacesContext context, ResponseWriter
writer, UIComponent column,
+ String facetName) throws IOException {
+ if (column.isRendered()) {
+
+ String classAttribute = facetName + "Class";
+ writer.startElement(HTML.TD_ELEM, column);
+ if ("header".equals(facetName)) {
+ writer.startElement(HTML.DIV_ELEM, column);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable-resizer-holder rich-extable-cell-width-"
+ + column.getId(), null);
+ writer.startElement(HTML.DIV_ELEM, column);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable-resizer", null);
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.DIV_ELEM);
+ }
+ writer.startElement(HTML.DIV_ELEM, column);
+ writer
+ .writeAttribute(HTML.CLASS_ATTRIBUTE,
HtmlUtil.concatClasses("rich-extable-" + facetName + "-cell",
+ "rich-extable-cell-width-" + column.getId(), (String)
column.getAttributes().get(classAttribute)),
+ null);
+ writer.startElement(HTML.DIV_ELEM, column);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-" +
facetName + "-cell-content", null);
+ UIComponent facet = column.getFacet(facetName);
+ if (facet != null && facet.isRendered()) {
+ facet.encodeAll(context);
+ }
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.TD_ELEM);
+ }
+ }
+
+ private void encodeHeaderOrFooter(RendererState state, String name) throws
IOException {
+ FacesContext context = state.getContext();
+ ResponseWriter writer = context.getResponseWriter();
+ UIDataTableBase table = state.getRow();
+ if (table.isColumnFacetPresent(name)) {
+ writer.startElement(HTML.DIV_ELEM, table);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
HtmlUtil.concatClasses("rich-extable-" + name, (String) table
+ .getAttributes().get(name + "Class")), null);
+ writer.startElement(HTML.TABLE_ELEMENT, table);
+ writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
+ writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
+ writer.startElement(HTML.TBOBY_ELEMENT, table);
+ writer.startElement(HTML.TR_ELEMENT, table);
+ for (state.startIterate(); state.hasNextPart();) {
+ Part part = state.nextPart();
+ PartName partName = part.getName();
+ Iterator<UIComponent> columns = part.getColumns().iterator();
+ if (columns.hasNext()) {
+ writer.startElement(HTML.TD_ELEM, table);
+ if (PartName.frozen.equals(partName) &&
"footer".equals(name)) {
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable-footer-align", null);
+ }
+ writer.startElement(HTML.DIV_ELEM, table);
+ if (PartName.frozen.equals(partName)) {
+ if ("header".equals(name)) {
+ writer
+ .writeAttribute(HTML.ID_ATTRIBUTE,
table.getClientId(context) + ":frozenHeader", null);
+ }
+ } else {
+ writer.writeAttribute(HTML.ID_ATTRIBUTE,
table.getClientId(context) + ":" + name, null);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable"
+ + ("footer".equals(name) ? "-footer"
: "") + "-part rich-extable-part-width", null);
+ }
+
+ String tableId = table.getClientId(context) + ":cf" +
name.charAt(0) + partName.name().charAt(0);
+ encodeStartUpdate(context, tableId);
+
+ writer.startElement(HTML.TABLE_ELEMENT, table);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, tableId, null);
+ writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0",
null);
+ writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0",
null);
+ writer.startElement(HTML.TBOBY_ELEMENT, table);
+ writer.startElement(HTML.TR_ELEMENT, table);
+ while (columns.hasNext()) {
+ encodeHeaderOrFooterCell(context, writer, columns.next(),
name);
+ }
+ writer.endElement(HTML.TR_ELEMENT);
+ writer.endElement(HTML.TBOBY_ELEMENT);
+ writer.endElement(HTML.TABLE_ELEMENT);
+
+ encodeEndUpdate(context);
+
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.TD_ELEM);
+ }
+ }
+ writer.endElement(HTML.TR_ELEMENT);
+ writer.endElement(HTML.TBOBY_ELEMENT);
+ writer.endElement(HTML.TABLE_ELEMENT);
+ writer.endElement(HTML.DIV_ELEM);
+ }
+ }
+
+ public void encodeHeader(RendererState state) throws IOException {
+ FacesContext context = state.getContext();
+ ResponseWriter writer = context.getResponseWriter();
+ UIDataTableBase table = state.getRow();
+
+ UIComponent header = table.getFacet("header");
+ if (header != null && header.isRendered()) {
+ String elementId = table.getClientId(context) + ":tfh";
+
+ encodeStartUpdate(context, elementId);
+
+ writer.startElement(HTML.DIV_ELEM, table);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, elementId, null);
+ header.encodeAll(context);
+ writer.endElement(HTML.DIV_ELEM);
+
+ encodeEndUpdate(context);
+ }
+
+ encodeHeaderOrFooter(state, "header");
+ }
+
+ public void encodeBody(RendererState state) throws IOException {
+ FacesContext context = state.getContext();
+ ResponseWriter writer = context.getResponseWriter();
+ UIDataTableBase table = state.getRow();
+ writer.startElement(HTML.DIV_ELEM, table);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) +
":b", null);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-body",
null);
+ if (table.getRowCount() == 0) {
+ UIComponent facet = table.getFacet("noData");
+ if (facet != null && facet.isRendered()) {
+ facet.encodeAll(context);
+ } else {
+ Object noDataLabel =
table.getAttributes().get("noDataLabel");
+ if (noDataLabel != null) {
+ writer.writeText(noDataLabel, "noDataLabel");
+ }
+ }
+ } else {
+ table.getAttributes().put("clientFirst", 0);
+ writer.startElement(HTML.DIV_ELEM, table);
+ writer.startElement(HTML.DIV_ELEM, table);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable-spacer", null);
+ writer.endElement(HTML.DIV_ELEM);
+ writer.startElement(HTML.TABLE_ELEMENT, table);
+ writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
+ writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
+ writer.startElement(HTML.TBOBY_ELEMENT, table);
+ writer.startElement(HTML.TR_ELEMENT, table);
+ for (state.startIterate(); state.hasNextPart();) {
+ writer.startElement(HTML.TD_ELEM, table);
+ writer.startElement(HTML.DIV_ELEM, table);
+ PartName partName = state.nextPart().getName();
+ if (PartName.normal.equals(partName)) {
+ writer.writeAttribute(HTML.ID_ATTRIBUTE,
table.getClientId(context) + ":body", null);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable-part rich-extable-part-width", null);
+ }
+
+ String targetId = table.getClientId(context) + ":tbt" +
partName.name().charAt(0);
+
+ encodeStartUpdate(context, targetId);
+
+ writer.startElement(HTML.TABLE_ELEMENT, table);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, targetId, null);
+ writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0",
null);
+ writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0",
null);
+ writer.startElement(HTML.TBOBY_ELEMENT, table);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) +
":tb"
+ + partName.toString().charAt(0), null);
+ encodeRows(state);
+ writer.endElement(HTML.TBOBY_ELEMENT);
+ writer.endElement(HTML.TABLE_ELEMENT);
+
+ encodeEndUpdate(context);
+
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.TD_ELEM);
+ }
+ writer.endElement(HTML.TR_ELEMENT);
+ writer.endElement(HTML.TBOBY_ELEMENT);
+ writer.endElement(HTML.TABLE_ELEMENT);
+ writer.endElement(HTML.DIV_ELEM);
+ }
+ writer.endElement(HTML.DIV_ELEM);
+ }
+
+ public void encodeFooter(RendererState state) throws IOException {
+ FacesContext context = state.getContext();
+ ResponseWriter writer = context.getResponseWriter();
+ UIDataTableBase table = state.getRow();
+
+ encodeHeaderOrFooter(state, "footer");
+
+ UIComponent footer = table.getFacet("footer");
+ if (footer != null && footer.isRendered()) {
+ String elementId = table.getClientId(context) + ":tff";
+
+ encodeStartUpdate(context, elementId);
+
+ writer.startElement(HTML.DIV_ELEM, table);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, elementId, null);
+ footer.encodeAll(context);
+ writer.endElement(HTML.DIV_ELEM);
+
+ encodeEndUpdate(context);
+ }
+ }
+
+ public void encodeMetaComponent(RendererState state, String metaComponentId)
throws IOException {
+ if (UIExtendedDataTable.HEADER.equals(metaComponentId)) {
+ encodeHeader(state);
+ } else if (UIExtendedDataTable.FOOTER.equals(metaComponentId)) {
+ encodeFooter(state);
+ } else if (UIExtendedDataTable.BODY.equals(metaComponentId)) {
+ encodeBody(state);
+ } else {
+ throw new IllegalArgumentException("Unsupported
metaComponentIdentifier: " + metaComponentId);
+ }
+ }
+ }
+
+ private class PartialTableEncoderStrategy extends BaseTableEncoderStrategy {
+ private void switchResponseWriter(FacesContext context, boolean writerState) {
+ ResponseWriter writer = context.getResponseWriter();
+ if (writer instanceof OnOffResponseWriter) {
+ ((OnOffResponseWriter) writer).setSwitchedOn(writerState);
+ }
+ }
+
+ private ResponseWriter install(FacesContext context) {
+ ResponseWriter writer = context.getResponseWriter();
+
+ assert !(writer instanceof OnOffResponseWriter);
+
+ context.setResponseWriter(new OnOffResponseWriter(writer));
+
+ return writer;
+ }
+
+ private void uninstall(FacesContext context, ResponseWriter
initialResponseWriter) {
+ ResponseWriter writer = context.getResponseWriter();
+
+ assert (writer instanceof OnOffResponseWriter);
+
+ context.setResponseWriter(initialResponseWriter);
+ }
+
+ public void encodeHeader(RendererState state) throws IOException {
+ FacesContext context = state.getContext();
+ ResponseWriter writer = install(context);
+ try {
+ super.encodeHeader(state);
+ } finally {
+ uninstall(context, writer);
+ }
+ };
+
+ public void encodeBody(RendererState state) throws IOException {
+ FacesContext context = state.getContext();
+ ResponseWriter writer = install(context);
+ try {
+ super.encodeBody(state);
+ } finally {
+ uninstall(context, writer);
+ }
+ };
+
+ public void encodeFooter(RendererState state) throws IOException {
+ FacesContext context = state.getContext();
+ ResponseWriter writer = install(context);
+ try {
+ super.encodeFooter(state);
+ } finally {
+ uninstall(context, writer);
+ }
+ };
+
+ void encodeStartUpdate(FacesContext context, String targetId) throws IOException
{
+ switchResponseWriter(context, true);
+
+
context.getPartialViewContext().getPartialResponseWriter().startUpdate(targetId);
+ }
+
+ void encodeEndUpdate(FacesContext context) throws IOException {
+ context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+
+ switchResponseWriter(context, false);
+ }
+ }
+
+ private BaseTableEncoderStrategy fullEncodeStrategy = new
BaseTableEncoderStrategy();
+
+ private BaseTableEncoderStrategy partialEncodeStrategy = new
PartialTableEncoderStrategy();
+
@Override
protected Class<? extends UIComponent> getComponentClass() {
return UIExtendedDataTable.class;
@@ -245,7 +543,8 @@
table.restoreOrigValue(context);
}
} else {
- throw new IllegalArgumentException("Unsupported metaComponentIdentifier:
" + metaComponentId);
+ RendererState state = createRowHolder(context, component);
+ partialEncodeStrategy.encodeMetaComponent(state, metaComponentId);
}
}
@@ -257,15 +556,8 @@
writer.writeAttribute(HTML.ID_ATTRIBUTE, component.getClientId(context), null);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
HtmlUtil.concatClasses("rich-extable", (String)
attributes.get("styleClass")), null);
getUtils().writeAttribute(writer, HTML.STYLE_ATTRIBUTE,
attributes.get("style"));
- UIComponent header = component.getFacet("header");
- if (header != null && header.isRendered()) {
- writer.startElement(HTML.DIV_ELEM, component);
- header.encodeAll(context);
- writer.endElement(HTML.DIV_ELEM);
- }
}
-
@Override
public RendererState createRowHolder(FacesContext context, UIComponent component) {
return new RendererState(context, (UIDataTableBase) component);
@@ -274,27 +566,22 @@
@Override
protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
throws IOException {
+
UIDataTableBase table = (UIDataTableBase) component;
Object key = table.getRowKey();
table.captureOrigValue(context);
table.setRowKey(context, null);
RendererState state = createRowHolder(context, table);
+ fullEncodeStrategy.encodeHeader(state);
encodeStyle(state);
- encodeHeaderOrFooter(state, "header");
- encodeBody(state);
- encodeHeaderOrFooter(state, "footer");
+ fullEncodeStrategy.encodeBody(state);
+ fullEncodeStrategy.encodeFooter(state);
table.setRowKey(context, key);
table.restoreOrigValue(context);
}
@Override
protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- UIComponent facet = component.getFacet("footer");
- if (facet != null && facet.isRendered()) {
- writer.startElement(HTML.DIV_ELEM, component);
- facet.encodeAll(context);
- writer.endElement(HTML.DIV_ELEM);
- }
writer.startElement(HTML.DIV_ELEM, component);
writer.writeAttribute(HTML.ID_ATTRIBUTE, component.getClientId(context) +
":d", null);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-drag",
null);
@@ -383,149 +670,6 @@
writer.endElement("style");
}
- private void encodeHeaderOrFooter(RendererState state, String name) throws
IOException {
- FacesContext context = state.getContext();
- ResponseWriter writer = context.getResponseWriter();
- UIDataTableBase table = state.getRow();
- if (table.isColumnFacetPresent(name)) {
- writer.startElement(HTML.DIV_ELEM, table);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
HtmlUtil.concatClasses("rich-extable-" + name, (String) table
- .getAttributes().get(name + "Class")), null);
- writer.startElement(HTML.TABLE_ELEMENT, table);
- writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
- writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
- writer.startElement(HTML.TBOBY_ELEMENT, table);
- writer.startElement(HTML.TR_ELEMENT, table);
- for (state.startIterate(); state.hasNextPart();) {
- Part part = state.nextPart();
- PartName partName = part.getName();
- Iterator<UIComponent> columns = part.getColumns().iterator();
- if (columns.hasNext()) {
- writer.startElement(HTML.TD_ELEM, table);
- if (PartName.frozen.equals(partName) &&
"footer".equals(name)) {
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable-footer-align", null);
- }
- writer.startElement(HTML.DIV_ELEM, table);
- if (PartName.frozen.equals(partName)) {
- if ("header".equals(name)) {
- writer
- .writeAttribute(HTML.ID_ATTRIBUTE,
table.getClientId(context) + ":frozenHeader", null);
- }
- } else {
- writer.writeAttribute(HTML.ID_ATTRIBUTE,
table.getClientId(context) + ":" + name, null);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable"
- + ("footer".equals(name) ? "-footer" :
"") + "-part rich-extable-part-width", null);
- }
- writer.startElement(HTML.TABLE_ELEMENT, table);
- writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0",
null);
- writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0",
null);
- writer.startElement(HTML.TBOBY_ELEMENT, table);
- writer.startElement(HTML.TR_ELEMENT, table);
- while (columns.hasNext()) {
- encodeHeaderOrFooterCell(context, writer, columns.next(), name);
- }
- writer.endElement(HTML.TR_ELEMENT);
- writer.endElement(HTML.TBOBY_ELEMENT);
- writer.endElement(HTML.TABLE_ELEMENT);
- writer.endElement(HTML.DIV_ELEM);
- writer.endElement(HTML.TD_ELEM);
- }
- }
- writer.endElement(HTML.TR_ELEMENT);
- writer.endElement(HTML.TBOBY_ELEMENT);
- writer.endElement(HTML.TABLE_ELEMENT);
- writer.endElement(HTML.DIV_ELEM);
- }
- }
-
- private void encodeBody(RendererState state) throws IOException {
- FacesContext context = state.getContext();
- ResponseWriter writer = context.getResponseWriter();
- UIDataTableBase table = state.getRow();
- writer.startElement(HTML.DIV_ELEM, table);
- writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) +
":b", null);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-body",
null);
- if (table.getRowCount() == 0) {
- UIComponent facet = table.getFacet("noData");
- if (facet != null && facet.isRendered()) {
- facet.encodeAll(context);
- } else {
- Object noDataLabel = table.getAttributes().get("noDataLabel");
- if (noDataLabel != null) {
- writer.writeText(noDataLabel, "noDataLabel");
- }
- }
- } else {
- table.getAttributes().put("clientFirst", 0);
- writer.startElement(HTML.DIV_ELEM, table);
- writer.startElement(HTML.DIV_ELEM, table);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-spacer",
null);
- writer.endElement(HTML.DIV_ELEM);
- writer.startElement(HTML.TABLE_ELEMENT, table);
- writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
- writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
- writer.startElement(HTML.TBOBY_ELEMENT, table);
- writer.startElement(HTML.TR_ELEMENT, table);
- for (state.startIterate(); state.hasNextPart();) {
- writer.startElement(HTML.TD_ELEM, table);
- writer.startElement(HTML.DIV_ELEM, table);
- PartName partName = state.nextPart().getName();
- if (PartName.normal.equals(partName)) {
- writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) +
":body", null);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-part
rich-extable-part-width", null);
- }
- writer.startElement(HTML.TABLE_ELEMENT, table);
- writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
- writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
- writer.startElement(HTML.TBOBY_ELEMENT, table);
- writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) +
":tb"
- + partName.toString().charAt(0), null);
- encodeRows(state);
- writer.endElement(HTML.TBOBY_ELEMENT);
- writer.endElement(HTML.TABLE_ELEMENT);
- writer.endElement(HTML.DIV_ELEM);
- writer.endElement(HTML.TD_ELEM);
- }
- writer.endElement(HTML.TR_ELEMENT);
- writer.endElement(HTML.TBOBY_ELEMENT);
- writer.endElement(HTML.TABLE_ELEMENT);
- writer.endElement(HTML.DIV_ELEM);
- }
- writer.endElement(HTML.DIV_ELEM);
- }
-
- private void encodeHeaderOrFooterCell(FacesContext context, ResponseWriter writer,
UIComponent column,
- String facetName) throws IOException {
- if (column.isRendered()) {
-
- String classAttribute = facetName + "Class";
- writer.startElement(HTML.TD_ELEM, column);
- if ("header".equals(facetName)) {
- writer.startElement(HTML.DIV_ELEM, column);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable-resizer-holder rich-extable-cell-width-"
- + column.getId(), null);
- writer.startElement(HTML.DIV_ELEM, column);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
"rich-extable-resizer", null);
- writer.endElement(HTML.DIV_ELEM);
- writer.endElement(HTML.DIV_ELEM);
- }
- writer.startElement(HTML.DIV_ELEM, column);
- writer
- .writeAttribute(HTML.CLASS_ATTRIBUTE,
HtmlUtil.concatClasses("rich-extable-" + facetName + "-cell",
- "rich-extable-cell-width-" + column.getId(), (String)
column.getAttributes().get(classAttribute)),
- null);
- writer.startElement(HTML.DIV_ELEM, column);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-" +
facetName + "-cell-content", null);
- UIComponent facet = column.getFacet(facetName);
- if (facet != null && facet.isRendered()) {
- facet.encodeAll(context);
- }
- writer.endElement(HTML.DIV_ELEM);
- writer.endElement(HTML.DIV_ELEM);
- writer.endElement(HTML.TD_ELEM);
- }
- }
-
@Override
public void encodeRow(RowHolderBase rowHolder) throws IOException {
FacesContext context = rowHolder.getContext();