Author: abelevich
Date: 2007-05-02 11:46:56 -0400 (Wed, 02 May 2007)
New Revision: 612
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnVisitor.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
Log:
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnVisitor.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnVisitor.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnVisitor.java 2007-05-02
15:46:56 UTC (rev 612)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public interface ColumnVisitor {
+ public void visit(FacesContext context, UIComponent component, ResponseWriter writer)
throws IOException;
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java 2007-05-02
15:46:56 UTC (rev 612)
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class ColumnWalker {
+
+ static void iterateOverKids(FacesContext context, UIComponent component, ColumnVisitor
visitor, ResponseWriter writer) throws IOException{
+
+ if(context == null || component == null){
+ throw new NullPointerException();
+ }
+
+ if(!component.isRendered()){
+ return ;
+ }
+
+ if(null != component.getChildren()){
+ writer.startElement(HTML.TR_ELEMENT, component);
+ writer.writeText("\n", null);
+
+ for (Iterator iter = component.getChildren().iterator(); iter.hasNext(); ) {
+ UIComponent kid = (UIComponent) iter.next();
+ if (kid.isRendered()) {
+ if (kid instanceof UIColumn){
+ visitor.visit(context, kid, writer);
+ }
+ }
+ }
+ writer.endElement(HTML.TR_ELEMENT);
+ writer.writeText("\n", null);
+ }
+ }
+}
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-05-02
15:46:36 UTC (rev 611)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-05-02
15:46:56 UTC (rev 612)
@@ -1,7 +1,12 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
import org.richfaces.component.UIScrollableGrid;
import org.richfaces.renderkit.CompositeRenderer;
@@ -11,7 +16,55 @@
*/
public abstract class ScrollableGridBaseRenderer extends CompositeRenderer {
+
+ private final String FOOTER_PART = "footer";
+ private final String HEADER_PART = "header";
+
+
+ private final ColumnVisitor headerRenderer = new ColumnVisitor(){
+
+ public void visit(FacesContext context, UIComponent component, ResponseWriter writer)
throws IOException {
+
+ writer.startElement(HTML.td_ELEM, component);
+ writer.writeText("\n", null);
+
+ if(component.getFacet(HEADER_PART) != null){
+ component = component.getFacet(HEADER_PART);
+ renderChild(context, component);
+ }
+ writer.endElement(HTML.td_ELEM);
+ writer.writeText("\n", null);
+ }
+ };
+
+ private final ColumnVisitor footerRenderer = new ColumnVisitor(){
+
+ public void visit(FacesContext context, UIComponent component, ResponseWriter writer)
throws IOException {
+ writer.startElement(HTML.td_ELEM, component);
+ writer.writeText("\n", null);
+
+ if(component.getFacet(FOOTER_PART) != null){
+ component = component.getFacet(HEADER_PART);
+ renderChild(context, component);
+ }
+ writer.endElement(HTML.td_ELEM);
+ writer.writeText("\n", null);
+ }
+ };
+
+ private final ColumnVisitor bodyRenderer = new ColumnVisitor(){
+
+ public void visit(FacesContext context, UIComponent component, ResponseWriter writer)
throws IOException {
+ writer.startElement(HTML.td_ELEM, component);
+ writer.writeText("\n", null);
+ renderChildren(context, component);
+ writer.endElement(HTML.td_ELEM);
+ writer.writeText("\n", null);
+ }
+ };
+
+
protected String getJavaScriptVarName(FacesContext context, UIScrollableGrid grid) {
String id = grid.getBaseClientId(context);
return "Richfaces_ScrollableGrid_" + id.replaceAll("[^A-Za-z0-9_]",
"_");
@@ -20,4 +73,22 @@
protected String getScriptContributions(FacesContext context, UIScrollableGrid grid) {
return super.getScriptContributions(getJavaScriptVarName(context, grid), context,
grid);
}
+
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ ColumnWalker.iterateOverKids(context, component, bodyRenderer, writer);
+ }
+
+ public void renderHeaders(FacesContext context, UIComponent component)throws
IOException{
+ ResponseWriter writer = context.getResponseWriter();
+ ColumnWalker.iterateOverKids(context, component, headerRenderer, writer);
+ }
+
+ public void renderFooters(FacesContext context, UIComponent component) throws
IOException{
+ ResponseWriter writer = context.getResponseWriter();
+ ColumnWalker.iterateOverKids(context, component, footerRenderer, writer);
+ }
}