Author: abelevich
Date: 2010-07-12 13:17:45 -0400 (Mon, 12 Jul 2010)
New Revision: 17970
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataGrid.java
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/DataGridRenderer.java
root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/tables.taglib.xml
Log:
add metacomponents support, rename nodata -> noData
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataGrid.java
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataGrid.java 2010-07-12
16:51:04 UTC (rev 17969)
+++
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataGrid.java 2010-07-12
17:17:45 UTC (rev 17970)
@@ -22,26 +22,52 @@
package org.richfaces.component;
+import java.io.IOException;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import javax.faces.component.UIComponent;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PreRenderComponentEvent;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.context.ExtendedVisitContextMode;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.renderkit.MetaComponentRenderer;
+import org.slf4j.Logger;
+
/**
* @author Anton Belevich
*
*/
-public class UIDataGrid extends UISequence implements Row {
+public class UIDataGrid extends UISequence implements Row, MetaComponentResolver,
MetaComponentEncoder {
public static final String HEADER_FACET_NAME = "header";
-
public static final String FOOTER_FACET_NAME = "footer";
-
public static final String CAPTION_FACET_NAME = "caption";
+ public static final String NODATA_FACET_NAME = "noData";
- public static final String NODATA_FACET_NAME = "nodata";
+ public static final String HEADER = "header";
+ public static final String FOOTER = "footer";
+ public static final String BODY = "body";
+
+ private static final Logger RENDERKIT_LOG = RichfacesLogger.RENDERKIT.getLogger();
+ private static final Set<String> SUPPORTED_META_COMPONENTS = new
HashSet<String>();
+
+ static {
+ SUPPORTED_META_COMPONENTS.add(HEADER);
+ SUPPORTED_META_COMPONENTS.add(FOOTER);
+ SUPPORTED_META_COMPONENTS.add(BODY);
+ }
+
+
enum PropertyKeys {
- columns
+ columns, elements
}
public int getColumns() {
@@ -52,6 +78,14 @@
getStateHelper().put(PropertyKeys.columns, count);
}
+ public int getElements() {
+ return (Integer)getStateHelper().eval(PropertyKeys.elements);
+ }
+
+ public void setElements(int count) {
+ getStateHelper().put(PropertyKeys.elements, count);
+ }
+
public Iterator<UIComponent> columns() {
//DataGrid doesn't work with column components
return null;
@@ -73,5 +107,83 @@
return getFacet(NODATA_FACET_NAME);
}
+ //TODO: copy from UIDataTableBase
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
+ context.getApplication().publishEvent(context, PreRenderComponentEvent.class,
this);
+ MetaComponentRenderer renderer = (MetaComponentRenderer) getRenderer(context);
+ renderer.encodeMetaComponent(context, this, metaComponentId);
+ }
+
+ protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback
callback) {
+ if (visitContext instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext)
visitContext;
+ if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER)
{
+ //TODO nick - call preEncodeBegin(...) and emit PreRenderEvent
+ VisitResult visitResult;
+
+ visitResult = extendedVisitContext.invokeMetaComponentVisitCallback(this,
callback, HEADER);
+
+ if (visitResult == VisitResult.ACCEPT){
+ //TODO:
+ } else if (visitResult == VisitResult.COMPLETE) {
+ return true;
+ }
+
+ visitResult = extendedVisitContext.invokeMetaComponentVisitCallback(this,
callback, FOOTER);
+
+ if (visitResult == VisitResult.ACCEPT) {
+ //TODO nick - visit footer?
+ } else if (visitResult == VisitResult.COMPLETE) {
+ return true;
+ }
+
+ if (visitResult == VisitResult.REJECT) {
+ return false;
+ }
+ }
+ }
+
+ return super.visitFixedChildren(visitContext, callback);
+ }
+
+ 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
+ setRowKey(visitContext.getFacesContext(), null);
+
+ VisitResult result =
extendedVisitContext.invokeMetaComponentVisitCallback(this, callback, BODY);
+
+ if (result == VisitResult.ACCEPT) {
+ //TODO nick - visit body?
+ } else {
+ return result == VisitResult.COMPLETE;
+ }
+ }
+ }
+
+ return super.visitDataChildren(visitContext, callback, visitRows);
+ }
+
+ public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent, String metaComponentId) {
+ if (SUPPORTED_META_COMPONENTS.contains(metaComponentId)) {
+ Object oldRowKey = getRowKey();
+
+ try {
+ setRowKey(facesContext, null);
+ return getClientId(facesContext) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
+ } finally {
+ try {
+ setRowKey(facesContext, oldRowKey);
+ } catch (Exception e) {
+ RENDERKIT_LOG.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ return null;
+ }
}
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/DataGridRenderer.java
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/DataGridRenderer.java 2010-07-12
16:51:04 UTC (rev 17969)
+++
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/DataGridRenderer.java 2010-07-12
17:17:45 UTC (rev 17970)
@@ -32,6 +32,7 @@
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIDataGrid;
+import org.richfaces.component.UIDataTableBase;
/**
* @author Anton Belevich
@@ -42,17 +43,24 @@
@ResourceDependency(name = "jquery.js"), @ResourceDependency(name =
"richfaces.js"),
@ResourceDependency(name = "richfaces-event.js"), @ResourceDependency(name
= "richfaces-base-component.js"),
@ResourceDependency(name = "datagrid.ecss")})
-public class DataGridRenderer extends AbstractRowsRenderer {
+public class DataGridRenderer extends AbstractRowsRenderer implements
MetaComponentRenderer {
private static final EncodeStrategy THEAD = new EncodeStrategy () {
public void begin(ResponseWriter writer, FacesContext context, UIComponent
component, Object[] params)
throws IOException {
+ UIDataGrid dataGrid = (UIDataGrid)component;
+ String clientId = dataGrid.getClientId(context) + ":h";
+
+ boolean partial = (Boolean)(Boolean)params[0];
+ if(partial) {
+
context.getPartialViewContext().getPartialResponseWriter().startUpdate(clientId);
+ }
- UIDataGrid dataGrid = (UIDataGrid)component;
int columns = dataGrid.getColumns();
writer.startElement(HTML.THEAD_ELEMENT, component);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, clientId , null);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg-thead", null);
writer.startElement(HTML.TR_ELEMENT, component);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg-h", null);
@@ -66,6 +74,11 @@
writer.endElement(HTML.TH_ELEM);
writer.endElement(HTML.TR_ELEMENT);
writer.endElement(HTML.THEAD_ELEMENT);
+
+ boolean partial = (Boolean)(Boolean)params[0];
+ if(partial) {
+ context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ }
}
};
@@ -73,11 +86,18 @@
public void begin(ResponseWriter writer, FacesContext context, UIComponent
component, Object[] params)
throws IOException {
-
+
UIDataGrid dataGrid = (UIDataGrid)component;
+ String clientId = dataGrid.getClientId(context) + ":f";
+
int columns = dataGrid.getColumns();
-
+ boolean partial = (Boolean)(Boolean)params[0];
+ if(partial) {
+
context.getPartialViewContext().getPartialResponseWriter().startUpdate(clientId);
+ }
+
writer.startElement(HTML.TFOOT_ELEMENT, component);
+
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg-tfoot", null);
writer.startElement(HTML.TR_ELEMENT, component);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg-f", null);
@@ -90,7 +110,12 @@
throws IOException {
writer.endElement(HTML.TD_ELEM);
writer.endElement(HTML.TR_ELEMENT);
- writer.endElement(HTML.THEAD_ELEMENT);
+ writer.endElement(HTML.TFOOT_ELEMENT);
+
+ boolean partial = (Boolean)(Boolean)params[0];
+ if(partial) {
+ context.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ }
}
};
@@ -110,13 +135,16 @@
private static final EncodeStrategy NODATA = new EncodeStrategy() {
public void begin(ResponseWriter writer, FacesContext context, UIComponent
component, Object[] params)
throws IOException {
- writer.startElement(HTML.CAPTION_ELEMENT, component);
+ writer.startElement(HTML.TR_ELEMENT, component);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg-nd", null);
+ writer.startElement(HTML.TD_ELEM, component);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg-nd-c", null);
}
public void end(ResponseWriter writer, FacesContext context, UIComponent
component, Object[] params)
throws IOException {
- writer.endElement(HTML.CAPTION_ELEMENT);
+ writer.endElement(HTML.TD_ELEM);
+ writer.endElement(HTML.TR_ELEMENT);
}
};
@@ -143,34 +171,55 @@
writer.endElement(HTML.TD_ELEM);
}
- public void encodeHeader(ResponseWriter writer, FacesContext facesContext,
UIDataGrid dataGrid) throws IOException {
+ public void encodeHeader(ResponseWriter writer, FacesContext facesContext,
UIDataGrid dataGrid, boolean partial) throws IOException {
UIComponent footerFacet = dataGrid.getHeaderFacet();
- encodeFacet(writer, facesContext, footerFacet, THEAD, dataGrid);
+ encodeFacet(writer, facesContext, footerFacet, THEAD, dataGrid, new Object[]
{partial});
}
- public void encodeFooter(ResponseWriter writer, FacesContext facesContext, UIDataGrid
dataGrid) throws IOException {
+ public void encodeFooter(ResponseWriter writer, FacesContext facesContext, UIDataGrid
dataGrid, boolean partial) throws IOException {
UIComponent footerFacet = dataGrid.getFooterFacet();
- encodeFacet(writer, facesContext, footerFacet, TFOOT, dataGrid);
+ encodeFacet(writer, facesContext, footerFacet, TFOOT, dataGrid, new Object[]
{partial});
}
public void encodeCaption(ResponseWriter writer, FacesContext facesContext,
UIDataGrid dataGrid) throws IOException {
UIComponent captionFacet = dataGrid.getCaptionFacet();
- encodeFacet(writer, facesContext, captionFacet, CAPTION, dataGrid);
+ encodeFacet(writer, facesContext, captionFacet, CAPTION, dataGrid, null);
}
- private void encodeNoData(ResponseWriter writer, FacesContext facesContext,
UIDataGrid dataGrid) throws IOException {
+ public void encodeNoData(ResponseWriter writer, FacesContext facesContext, UIDataGrid
dataGrid) throws IOException {
UIComponent noDataFacet = dataGrid.getNoDataFacet();
- encodeFacet(writer, facesContext, noDataFacet, NODATA, dataGrid);
+ encodeFacet(writer, facesContext, noDataFacet, NODATA, dataGrid, null);
}
- private void encodeFacet(ResponseWriter writer, FacesContext facesContext,
UIComponent facet, EncodeStrategy strategy, UIDataGrid dataGrid) throws IOException{
+ public void encodeFacet(ResponseWriter writer, FacesContext facesContext, UIComponent
facet, EncodeStrategy strategy, UIDataGrid dataGrid, Object [] params) throws
IOException{
if(facet != null && facet.isRendered()) {
- strategy.begin(writer, facesContext, dataGrid, null);
+ strategy.begin(writer, facesContext, dataGrid, params);
facet.encodeAll(facesContext);
- strategy.end(writer, facesContext, dataGrid, null);
+ strategy.end(writer, facesContext, dataGrid, params);
}
}
+
+ public void encodeTBody(ResponseWriter writer, FacesContext facesContext, UIDataGrid
dataGrid, boolean partial) throws IOException {
+ String clientId = dataGrid.getClientId(facesContext) + ":dgb";
+ if(partial) {
+
facesContext.getPartialViewContext().getPartialResponseWriter().startUpdate(clientId);
+ }
+ writer.startElement(HTML.TBODY_ELEMENT, dataGrid);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, clientId , null);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg-body", null);
+ if(dataGrid.getRowCount() > 0) {
+ processRows(writer, facesContext, dataGrid, null);
+ } else {
+ encodeNoData(writer, facesContext, dataGrid);
+ }
+ writer.endElement(HTML.TBODY_ELEMENT);
+
+ if(partial) {
+ facesContext.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ }
+ }
+
@Override
protected void doEncodeChildren(ResponseWriter writer, FacesContext facesContext,
UIComponent component)
throws IOException {
@@ -180,17 +229,10 @@
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg", null);
encodeCaption(writer, facesContext, dataGrid);
- encodeHeader(writer, facesContext, dataGrid);
- encodeFooter(writer, facesContext, dataGrid);
+ encodeHeader(writer, facesContext, dataGrid, false);
+ encodeFooter(writer, facesContext, dataGrid, false);
+ encodeTBody(writer, facesContext, dataGrid, false);
- writer.startElement(HTML.TBODY_ELEMENT, dataGrid);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-dg", null);
- if(dataGrid.getRowCount() > 0) {
- processRows(writer, facesContext, dataGrid, null);
- } else {
- encodeNoData(writer, facesContext, dataGrid);
- }
- writer.endElement(HTML.TBODY_ELEMENT);
writer.endElement(HTML.TABLE_ELEMENT);
}
@@ -203,4 +245,19 @@
protected Class<? extends UIComponent> getComponentClass() {
return UIDataGrid.class;
}
+
+ public void encodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId)
+ throws IOException {
+ UIDataGrid table = (UIDataGrid) component;
+
+ if (UIDataTableBase.HEADER.equals(metaComponentId)) {
+ encodeHeader(context.getResponseWriter(), context, table, true);
+ } else if (UIDataTableBase.FOOTER.equals(metaComponentId)) {
+ encodeFooter(context.getResponseWriter(), context, table, true);
+ } else if(UIDataTableBase.BODY.equals(metaComponentId)) {
+ encodeTBody(context.getResponseWriter(), context, table, true);
+ } else {
+ throw new IllegalArgumentException("Unsupported metaComponentIdentifier:
" + metaComponentId);
+ }
+ }
}
Modified: root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/tables.taglib.xml
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/tables.taglib.xml 2010-07-12
16:51:04 UTC (rev 17969)
+++
root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/tables.taglib.xml 2010-07-12
17:17:45 UTC (rev 17970)
@@ -51,6 +51,7 @@
<component>
<component-type>org.richfaces.DataGrid</component-type>
<renderer-type>org.richfaces.DataGridRenderer</renderer-type>
+ <handler-class>org.richfaces.taglib.DataGridHandler</handler-class>
</component>
</tag>