Author: abelevich
Date: 2009-10-19 05:10:58 -0400 (Mon, 19 Oct 2009)
New Revision: 15720
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataIterator.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/FixedChildrenIterator.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/SubtableFixedChildrenIterator.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumnGroup.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/CellRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/HeaderEncodeStrategy.java
Removed:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/ColumnsIterator.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISimpleDataTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumn.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRendererBase.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/TableHolder.java
Log:
add asupport for the header, footer, caption facets
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/ColumnsIterator.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/ColumnsIterator.java 2009-10-16
17:19:51 UTC (rev 15719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/ColumnsIterator.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -30,16 +30,17 @@
* @author asmirnov
*
*/
-class ColumnsIterator implements Iterator<UIColumn>{
+class ColumnsIterator implements Iterator<UIComponent> {
- private UIColumn next;
+ private UIComponent next;
private boolean initialized = false;
protected Iterator<UIComponent> childrenIterator;
- public ColumnsIterator(UISimpleDataTable dataTable) {
+
+ public ColumnsIterator(UIComponent dataTable) {
this.childrenIterator = dataTable.getChildren().iterator();
}
@@ -51,11 +52,11 @@
return null != next;
}
- public UIColumn next() {
+ public UIComponent next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
- UIColumn result = next;
+ UIComponent result = next;
next = nextColumn();
return result;
}
@@ -64,16 +65,14 @@
throw new UnsupportedOperationException("Iterator is read-only");
}
- protected UIColumn nextColumn(){
- UIColumn nextColumn = null;
+ protected UIComponent nextColumn(){
while (childrenIterator != null && childrenIterator.hasNext()) {
UIComponent child = childrenIterator.next();
- if(child instanceof UIColumn){
- nextColumn = (UIColumn)child;
- break;
+ if(child instanceof UIColumn || child instanceof Column){
+ return child;
}
}
- return nextColumn;
+ return null;
}
}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataIterator.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataIterator.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataIterator.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -0,0 +1,78 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+
+class DataIterator extends ColumnsIterator {
+
+ protected Iterator<UIComponent> facetsIterator;
+
+ public DataIterator(UIComponent dataTable) {
+ super(dataTable);
+ facetsIterator = dataTable.getFacets().values().iterator();
+ }
+
+ @Override
+ protected UIComponent nextColumn() {
+ UIComponent nextColumn = null;
+ while (null == nextColumn && childrenIterator.hasNext()) {
+ UIComponent child = childrenIterator.next();
+ if (child.isRendered()) {
+ if (child instanceof UIColumn || child instanceof Column) {
+ nextColumn = child;
+ } /*else if (checkAjaxComponent(child)) {
+ nextColumn = child;
+ } */
+ }
+ }
+ /*
+ while (null == nextColumn && facetsIterator.hasNext()) {
+ UIComponent child = facetsIterator.next();
+ if (checkAjaxComponent(child)) {
+ nextColumn = child;
+ break;
+ }
+ }*/
+ return nextColumn;
+ }
+
+ /**
+ * @param child
+ * @return
+ */
+ protected Iterator<UIComponent> getColumnChildrenIterator(UIComponent child) {
+ return child.getChildren().iterator();
+ }
+
+ /**
+ * @param child
+ * @return
+ */
+ /*
+ protected boolean checkAjaxComponent(UIComponent child) {
+ return child instanceof AjaxSupport || child instanceof Dropzone;
+ }
+ */
+}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/FixedChildrenIterator.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/FixedChildrenIterator.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/FixedChildrenIterator.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -0,0 +1,106 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+
+class FixedChildrenIterator extends DataIterator {
+
+ private Iterator<UIComponent> currentColumnIterator;
+
+ public FixedChildrenIterator(UIComponent dataTable) {
+ super(dataTable);
+ }
+
+ @Override
+ protected UIComponent nextColumn() {
+ UIComponent nextColumn = null;
+ if (null != currentColumnIterator) {
+ nextColumn = currentColumnIterator.next();
+ checkNextColumnChild();
+ } else {
+ while (null == nextColumn && childrenIterator.hasNext()) {
+ UIComponent child = childrenIterator.next();
+ if (child instanceof UIColumn || child instanceof Column) {
+ boolean rendered = true;
+ try {
+ rendered = child.isRendered();
+ } catch (Exception e) {
+ // This exception can be thrown for a header/footer
+ // facets
+ // there column rendered attribute was binded to a row
+ // variable.
+ }
+ if (rendered) {
+ Iterator<UIComponent> iterator = getColumnChildrenIterator(child);
+ if (iterator.hasNext()) {
+ currentColumnIterator = iterator;
+ nextColumn = currentColumnIterator.next();
+ checkNextColumnChild();
+ }
+
+ }
+ } /*else if (checkAjaxComponent(child)) {
+ nextColumn = child;
+ }*/
+ }
+ }
+ if (null == nextColumn) {
+ nextColumn = getNextFacet();
+ }
+ return nextColumn;
+ }
+
+ /**
+ * @param nextColumn
+ * @return
+ */
+ protected UIComponent getNextFacet() {
+ UIComponent nextColumn = null;
+ /*while (null == nextColumn && facetsIterator.hasNext()) {
+ UIComponent child = facetsIterator.next();
+ if (checkAjaxComponent(child)) {
+ nextColumn = child;
+ }
+ }*/
+ return nextColumn;
+ }
+
+ /*@Override
+ protected boolean checkAjaxComponent(UIComponent child) {
+ return !super.checkAjaxComponent(child);
+ }*/
+
+ @Override
+ protected Iterator<UIComponent> getColumnChildrenIterator(UIComponent child) {
+ return child.getFacets().values().iterator();
+ }
+
+ protected void checkNextColumnChild() {
+ if (!currentColumnIterator.hasNext()) {
+ currentColumnIterator = null;
+ }
+ }
+
+}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/SubtableFixedChildrenIterator.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/SubtableFixedChildrenIterator.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/SubtableFixedChildrenIterator.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -0,0 +1,39 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import javax.faces.component.UIComponent;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class SubtableFixedChildrenIterator extends FixedChildrenIterator {
+
+ public SubtableFixedChildrenIterator(UIComponent dataTable) {
+ super(dataTable);
+ }
+
+ @Override
+ protected UIComponent getNextFacet() {
+ return null;
+ }
+}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java 2009-10-16
17:19:51 UTC (rev 15719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -1,10 +1,6 @@
package org.richfaces.component;
-/**
- * @author Anton Belevich
- *
- */
-public class UIColumn extends javax.faces.component.UIColumn {
+public abstract class UIColumn extends javax.faces.component.UIColumn implements Column
{
}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumnGroup.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumnGroup.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumnGroup.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -0,0 +1,57 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIPanel;
+
+/**
+ * JSF component class
+ *
+ */
+public abstract class UIColumnGroup extends UIPanel implements Row {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.Colgroup";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Colgroup";
+
+ public Iterator<UIComponent> columns(){
+ return new ColumnsIterator(this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.Column#isBreakBefore()
+ */
+ public boolean isBreakBefore() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.Column#setBreakBefore(boolean)
+ */
+ public void setBreakBefore(boolean newBreakBefore) {
+ throw new IllegalStateException("Property 'breakBefore' for subtable is
read-only");
+ }
+
+}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -0,0 +1,25 @@
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+public class UIDataTable extends UISequence{
+
+ public Iterator<UIComponent> columns() {
+ return new ColumnsIterator(this);
+ }
+
+ public UIComponent getHeader() {
+ return getFacet("header");
+ }
+
+ public UIComponent getFooter() {
+ return getFacet("footer");
+ }
+
+ public UIComponent getCaption() {
+ return getFacet("caption");
+ }
+
+}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISimpleDataTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISimpleDataTable.java 2009-10-16
17:19:51 UTC (rev 15719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISimpleDataTable.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -1,6 +1,5 @@
package org.richfaces.component;
-import java.util.Iterator;
@@ -10,9 +9,5 @@
*
*/
-public abstract class UISimpleDataTable extends UISequence {
-
- public Iterator<UIColumn> columns() {
- return new ColumnsIterator(this);
- }
+public abstract class UISimpleDataTable extends UIDataTable {
}
\ No newline at end of file
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -0,0 +1,81 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+
+/**
+ * JSF component class
+ *
+ */
+public abstract class UISubTable extends UIDataTable implements Row {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.SubTable";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.SubTable";
+
+
+ @Override
+ public Iterator<UIComponent> fixedChildren() {
+ return new SubtableFixedChildrenIterator(this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.Column#isBreakBefore()
+ */
+ public boolean isBreakBefore() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.Column#setBreakBefore(boolean)
+ */
+ public void setBreakBefore(boolean newBreakBefore) {
+ throw new IllegalStateException("Property 'breakBefore' for subtable is
read-only");
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.UIDataTable#columns()
+ */
+ public Iterator<UIComponent> columns() {
+ return super.columns();
+ }
+
+ /**
+ * @return the sortExpression
+ */
+ public String getSortExpression() {
+ // SubTable is not sortable element.
+ return null;
+ }
+
+ /**
+ * @param sortExpression the sortExpression to set
+ */
+ public void setSortExpression(String sortExpression) {
+ // Do nothing - subtable is not sortable element;
+ }
+
+}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumn.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumn.java 2009-10-16
17:19:51 UTC (rev 15719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumn.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -1,8 +1,67 @@
package org.richfaces.component.html;
+import javax.el.MethodExpression;
+
import org.richfaces.component.UIColumn;
+import org.richfaces.model.Ordering;
-public class HtmlColumn extends UIColumn{
+public class HtmlColumn extends UIColumn {
public static final String COMPONENT_TYPE = "org.richfaces.Column";
public static final String COMPONENT_FAMILY = "org.richfaces.Column";
+
+ public MethodExpression getFilterMethod() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public String getFilterValue() {
+ return null;
+ }
+ public String getSortExpression() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public Ordering getSortOrder() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public boolean isBreakBefore() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ public boolean isSelfSorted() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ public boolean isSortable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ public void setBreakBefore(boolean newBreakBefore) {
+ // TODO Auto-generated method stub
+
+ }
+ public void setFilterMethod(MethodExpression methodExpression) {
+ // TODO Auto-generated method stub
+
+ }
+ public void setFilterValue(String filterValue) {
+ // TODO Auto-generated method stub
+
+ }
+ public void setSelfSorted(boolean selfSorted) {
+ // TODO Auto-generated method stub
+
+ }
+ public void setSortExpression(String sortExpression) {
+ // TODO Auto-generated method stub
+
+ }
+ public void setSortOrder(Ordering sortOrder) {
+ // TODO Auto-generated method stub
+
+ }
+ public void setSortable(boolean sortable) {
+ // TODO Auto-generated method stub
+ }
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2009-10-16
17:19:51 UTC (rev 15719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -22,6 +22,7 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -31,7 +32,9 @@
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.Row;
import org.richfaces.component.UIDataAdaptor;
+import org.richfaces.component.UIDataTable;
/**
* @author shura
@@ -49,7 +52,7 @@
{"onmouseout","onRowMouseOut"}
};
-/*
+
public static final String ROW_CLASS_KEY =
AbstractRowsRenderer.class.getName() + ".rowClass";
@@ -64,7 +67,7 @@
public static final String SKIN_FIRST_ROW_CLASS_KEY =
AbstractRowsRenderer.class.getName() + ".firstRowSkinClass";
-*/
+
/*
* (non-Javadoc)
*
@@ -83,15 +86,15 @@
encodeOneRow(facesContext, holder);
writer.endElement(HTML.TR_ELEMENT);
}catch (IOException e) {
- //???
+ //TODO: seems we need add throws IOException ???
}
holder.nextRow();
return DataVisitResult.CONTINUE;
}
- public void encodeRows(FacesContext facesContext, UIComponent component) throws
IOException {
- encodeRows(facesContext, component, new TableHolder((UIDataAdaptor) component));
+ public void encodeRows(FacesContext facesContext, UIDataTable table) throws IOException
{
+ encodeRows(facesContext, table, new TableHolder(table));
}
@@ -103,9 +106,9 @@
* @param component
* @throws IOException
*/
- protected void encodeRows(FacesContext context, UIComponent component, TableHolder
tableHolder)
+ protected void encodeRows(FacesContext context, UIDataTable component, TableHolder
tableHolder)
throws IOException {
- UIDataAdaptor table = (UIDataAdaptor) component;
+ UIDataTable table = component;
Object key = table.getRowKey();
table.captureOrigValue(context);
@@ -139,15 +142,15 @@
return true;
}
- public void encodeChildren(FacesContext context, UIComponent component)
- throws IOException {
- encodeRows(context, component);
+ public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
+ if(component instanceof UIDataTable) {
+ encodeRows(context, (UIDataTable)component);
+ }
}
- public void encodeCaption(FacesContext context, UIDataAdaptor table) throws IOException
{
- /*
-
- UIComponent caption = table.getFacet("caption");
+ public void encodeCaption(FacesContext context, UIDataTable table) throws IOException {
+
+ UIComponent caption = table.getCaption();
if (caption == null) {
return;
}
@@ -171,7 +174,7 @@
renderChild(context, caption);
writer.endElement("caption");
- */
+
}
/**
@@ -208,7 +211,7 @@
protected void encodeStyleClass(ResponseWriter writer, Object parentPredefined, Object
predefined,
Object parent, Object custom) throws IOException {
- /*
+
StringBuffer styleClass = new StringBuffer();
// Construct predefined classes
@@ -227,12 +230,12 @@
}
if (styleClass.length() > 0) {
writer.writeAttribute(HTML.class_ATTRIBUTE, styleClass, "styleClass");
- } */
+ }
}
protected void encodeStyle(ResponseWriter writer, Object parentPredefined,
Object predefined, Object parent, Object custom) throws IOException {
- /*
+
StringBuffer style = new StringBuffer();
// Construct predefined styles
if (null != parentPredefined) {
@@ -250,7 +253,7 @@
if (style.length() > 0) {
writer.writeAttribute("style", style, "style");
}
- */
+
}
@@ -273,7 +276,7 @@
protected void encodeCellChildren(FacesContext context, UIComponent cell,
String skinFirstRowClass, String skinRowClass, String rowClass,
String skinCellClass, String cellClass) throws IOException {
- /*
+
Map<String, Object> requestMap =
context.getExternalContext().getRequestMap();
// Save top level class parameters ( if any ), and put new for this
// component
@@ -310,29 +313,29 @@
requestMap.put(SKIN_FIRST_ROW_CLASS_KEY, savedSkinFirstRowClass);
requestMap.put(SKIN_ROW_CLASS_KEY, savedSkinRowClass);
requestMap.put(SKIN_CELL_CLASS_KEY, savedSkinCellClass);
- */
+
}
protected void encodeTableHeaderFacet(FacesContext context, int columns, ResponseWriter
writer, UIComponent footer, String skinFirstRowClass, String skinRowClass, String
skinCellClass, String footerClass, String element) throws IOException {
-// boolean isColgroup = footer instanceof Row;
-// if (!isColgroup) {
-// writer.startElement("tr", footer);
-// encodeStyleClass(writer, null, skinFirstRowClass, footerClass, null);
-// writer.startElement(element, footer);
-// encodeStyleClass(writer, null, skinCellClass, footerClass, null);
-// if (columns > 0) {
-// writer.writeAttribute("colspan", String.valueOf(columns), null);
-// }
-// writer.writeAttribute("scope", "colgroup", null);
-// }
-//
-// encodeCellChildren(context, footer, skinFirstRowClass, skinRowClass,
-// footerClass, skinCellClass, null);
-//
-// if (!isColgroup) {
-// writer.endElement(element);
-// writer.endElement("tr");
-// }
+ boolean isColgroup = footer instanceof Row;
+ if (!isColgroup) {
+ writer.startElement("tr", footer);
+ encodeStyleClass(writer, null, skinFirstRowClass, footerClass, null);
+ writer.startElement(element, footer);
+ encodeStyleClass(writer, null, skinCellClass, footerClass, null);
+ if (columns > 0) {
+ writer.writeAttribute("colspan", String.valueOf(columns), null);
+ }
+ writer.writeAttribute("scope", "colgroup", null);
+ }
+
+ encodeCellChildren(context, footer, skinFirstRowClass, skinRowClass,
+ footerClass, skinCellClass, null);
+
+ if (!isColgroup) {
+ writer.endElement(element);
+ writer.endElement("tr");
+ }
}
}
Deleted:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-10-16
17:19:51 UTC (rev 15719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -1,70 +0,0 @@
-package org.richfaces.renderkit;
-
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.UIColumn;
-import org.richfaces.component.UIDataAdaptor;
-import org.richfaces.component.UISimpleDataTable;
-
-@ResourceDependencies({
- @ResourceDependency(library = "javax.faces", name = "jsf.js"),
- @ResourceDependency(name = "jquery.js"),
- @ResourceDependency(name = "richfaces.js")
-})
-public abstract class AbstractTableRenderer extends AbstractRowsRenderer {
-
- public void encodeTableStructure(FacesContext context, UIComponent component) throws
IOException{
- ResponseWriter writer = context.getResponseWriter();
- writer.writeText("Encoding dataTable caption, colgroup, defenitions, headers
etc",component, null);
- }
-
- @Override
- public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
- encodeTBody(context, (UIDataAdaptor) component);
- }
-
- public void encodeTBody (FacesContext context, UIDataAdaptor table) throws IOException
{
- String clientId = table.getClientId(context);
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement("tbody", table);
- writer.writeAttribute("id", clientId + ":tb", null);
- encodeRows(context, table);
- writer.endElement("tbody");
- }
-
-
- @Override
- public void encodeOneRow(FacesContext facesContext, TableHolder holder) throws
IOException {
- ResponseWriter writer = facesContext.getResponseWriter();
- UISimpleDataTable table = (UISimpleDataTable)holder.getTable();
- Iterator<UIColumn> columns = table.columns();
- while (columns.hasNext()) {
- UIColumn column = columns.next();
- if(column.isRendered()) {
- encodeRowStart(writer, column);
- encodeRow(facesContext, writer, column);
- encodeRowEnd(writer, column);
- }
- }
- }
-
- private void encodeRowStart(ResponseWriter writer, UIColumn column) throws IOException
{
- writer.startElement(HTML.td_ELEM, column);
- }
-
- private void encodeRowEnd(ResponseWriter writer, UIColumn column) throws IOException {
- writer.endElement(HTML.td_ELEM);
- }
-
- private void encodeRow(FacesContext facesContext, ResponseWriter writer, UIColumn
column) throws IOException {
- renderChildren(facesContext, column);
- }
-}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/CellRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/CellRenderer.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/CellRenderer.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -0,0 +1,133 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.renderkit.RendererBase;
+
+/**
+ * @author shur
+ * modified by Alexej Kushunin
+ *
+ */
+public class CellRenderer extends RendererBase {
+
+ public String styleClass(FacesContext context , UIComponent component){
+ StringBuffer styleClass = new StringBuffer();
+ // Construct predefined classes
+ Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+ Object parentPredefined = requestMap.get(AbstractRowsRenderer.SKIN_CELL_CLASS_KEY);
+ if (null != parentPredefined) {
+ styleClass.append(parentPredefined).append(" ");
+ } else {
+ styleClass.append("rich-table-cell ");
+ }
+ // Append class from parent component.
+ Object parent = requestMap.get(AbstractRowsRenderer.CELL_CLASS_KEY);
+ if (null != parent) {
+ styleClass.append(parent).append(" ");
+ }
+ Object custom = component.getAttributes().get("styleClass");
+ if (null != custom) {
+ styleClass.append(custom);
+ }
+ return styleClass.toString();
+ }
+
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+
+ super.doEncodeBegin(writer, context, component);
+ java.lang.String clientId = component.getClientId(context);
+ boolean isHeader = (styleClass(context, component)).contains("header");
+ if(isHeader)
+ {
+ writer.startElement("th", component);
+
+ }else{
+
+ writer.startElement("td", component);
+ }
+
+
+ getUtils().writeAttribute(writer, "class", styleClass(context,component) );
+ getUtils().writeAttribute(writer, "id", clientId );
+ getUtils().encodeAttributesFromArray(context,component,new String[] {
+ "abbr" ,
+ "align" ,
+ "axis" ,
+ "bgcolor" ,
+ "char" ,
+ "charoff" ,
+ "colspan" ,
+ "dir" ,
+ "headers" ,
+ "height" ,
+ "lang" ,
+ "nowrap" ,
+ "onclick" ,
+ "ondblclick" ,
+ "onkeydown" ,
+ "onkeypress" ,
+ "onkeyup" ,
+ "onmousedown" ,
+ "onmousemove" ,
+ "onmouseout" ,
+ "onmouseover" ,
+ "onmouseup" ,
+ "rowspan" ,
+ "scope" ,
+ "style" ,
+ "title" ,
+ "valign" ,
+ "width" ,
+ "xml:lang" });
+
+ }
+
+
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ // TODO Auto-generated method stub
+ super.doEncodeEnd(writer, context, component);
+ boolean isHeader = (styleClass(context, component)).contains("header");
+ if(isHeader)
+ {
+ writer.endElement("th");
+
+ }else{
+
+ writer.endElement("td");
+ }
+ }
+
+ protected Class<? extends UIComponent> getComponentClass() {
+
+ return UIColumn.class;
+ }
+
+}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/HeaderEncodeStrategy.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/HeaderEncodeStrategy.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/HeaderEncodeStrategy.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -0,0 +1,38 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+public interface HeaderEncodeStrategy {
+
+ public abstract void encodeBegin(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn) throws IOException;
+
+ public abstract void encodeEnd(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn) throws IOException;
+
+}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRendererBase.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRendererBase.java 2009-10-16
17:19:51 UTC (rev 15719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRendererBase.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -1,15 +1,453 @@
package org.richfaces.renderkit;
+import java.io.IOException;
+import java.util.Iterator;
+
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
-/**
- * @author Anton Belevich
- *
- */
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.Column;
+import org.richfaces.component.Row;
+import org.richfaces.component.UIDataTable;
@ResourceDependencies({
- @ResourceDependency(name = "simple-datatable.js")
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "simple-datatable.js"),
+ @ResourceDependency(name = "table.css")
})
-public abstract class SimpleDataTableRendererBase extends AbstractTableRenderer {
+
+public abstract class SimpleDataTableRendererBase extends AbstractRowsRenderer {
+
+ public void encodeTableStructure(FacesContext context, UIDataTable table) throws
IOException{
+
+ Object key = table.getRowKey();
+ table.captureOrigValue(context);
+ table.setRowKey(context, null);
+
+ encodeCaption(context, table);
+
+ // Encode colgroup definition.
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement("colgroup", table);
+ int columns = getColumnsCount(table);
+ writer.writeAttribute("span", String.valueOf(columns), null);
+ String columnsWidth = (String) table.getAttributes().get("columnsWidth");
+
+ if (null != columnsWidth) {
+ String[] widths = columnsWidth.split(",");
+ for (int i = 0; i < widths.length; i++) {
+ writer.startElement("col", table);
+ writer.writeAttribute("width", widths[i], null);
+ writer.endElement("col");
+ }
+ }
+ writer.endElement("colgroup");
+
+ encodeHeader(context, table, columns);
+ encodeFooter(context, table, columns);
+
+ table.setRowKey(context,key);
+ table.restoreOrigValue(context);
+ }
+
+ protected boolean isColumnRendered(UIComponent component) {
+ try {
+ return component.isRendered();
+ } catch(Exception e){
+ // DO nothing, rendered binded to row variable;
+ }
+ return true;
+ }
+
+ public boolean isColumnFacetPresent(UIDataTable table, String facetName) {
+ Iterator<UIComponent> columns = table.columns();
+ boolean result = false;
+ while(columns.hasNext() && !result) {
+ UIComponent component = columns.next();
+ if(isColumnRendered(component)){
+ if(null != component.getFacet(facetName)){
+ result = true;
+ }
+ }
+ }
+ return result;
+ }
+
+ protected boolean isEncodeHeaders(UIDataTable table) {
+ return isColumnFacetPresent(table, "header") ||
+ isHeaderFactoryColumnAttributePresent(table, "sortBy") ||
+ isHeaderFactoryColumnAttributePresent(table, "comparator") ||
+ isHeaderFactoryColumnAttributePresent(table, "filterBy");
+ }
+
+ /**
+ * 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
+ */
+ public boolean isHeaderFactoryColumnAttributePresent(UIDataTable table,
+ String attributeName) {
+ Iterator<UIComponent> columns = table.columns();
+ boolean result = false;
+
+ while (columns.hasNext() && !result) {
+ UIComponent column = columns.next();
+ if (isColumnRendered(column)) {
+ if (null != column.getValueExpression(attributeName)) {
+ result = true;
+ }
+ }
+ }
+ return result;
+ }
+
+ protected void encodeHeaderFacets(FacesContext context, ResponseWriter writer,
Iterator<UIComponent> headers,
+ String skinCellClass, String headerClass, String facetName, String element, int
colCount) throws IOException {
+ int t_colCount = 0;
+
+ HeaderEncodeStrategy richEncodeStrategy = new RichHeaderEncodeStrategy();
+ HeaderEncodeStrategy simpleEncodeStrategy = new SimpleHeaderEncodeStrategy();
+
+ while (headers.hasNext()) {
+ UIComponent column = (UIComponent) headers.next();
+ if (!isColumnRendered(column)) {
+ continue;
+ }
+
+ Integer colspan = (Integer) column.getAttributes().get("colspan");
+ if (colspan != null && colspan.intValue() > 0) {
+ t_colCount += colspan.intValue();
+ } else {
+ t_colCount++;
+ }
+
+ if (t_colCount > colCount) {
+ break;
+ }
+
+ String classAttribute = facetName + "Class";
+ String columnHeaderClass = (String) column.getAttributes().get(classAttribute);
+
+ writer.startElement(element, column);
+ encodeStyleClass(writer, null, skinCellClass, headerClass, columnHeaderClass);
+ writer.writeAttribute("scope", "col", null);
+ getUtils().encodeAttribute(context, column, "colspan");
+
+ boolean sortableColumn = column.getValueExpression("comparator") != null
+ || column.getValueExpression("sortBy") != null;
+
+ HeaderEncodeStrategy strategy = (column instanceof org.richfaces.component.UIColumn
+ && "header".equals(facetName)) ? richEncodeStrategy :
simpleEncodeStrategy;
+
+ strategy.encodeBegin(context, writer, column, facetName, sortableColumn);
+
+ UIComponent facet = column.getFacet(facetName);
+ if (facet != null && isColumnRendered(facet)) {
+ renderChild(context, facet);
+ }
+
+ strategy.encodeEnd(context, writer, column, facetName, sortableColumn);
+
+ writer.endElement(element);
+ }
+ }
+
+ public void encodeHeader(FacesContext context, UIDataTable table, int columns) throws
IOException {
+
+ UIComponent header = table.getHeader();
+ boolean isEncodeHeaders = isEncodeHeaders(table);
+
+ if (header != null || isEncodeHeaders) {
+
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement("thead", table);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-table-thead", null);
+ String headerClass = (String) table.getAttributes().get("headerClass");
+ if (header != null) {
+ encodeTableHeaderFacet(context, columns, writer, header,
+ "rich-table-header",
+ "rich-table-header-continue",
+ "rich-table-headercell",
+ headerClass, "th");
+ }
+
+ if (isEncodeHeaders) {
+ writer.startElement("tr", table);
+ encodeStyleClass(writer, null, "rich-table-subheader", null, headerClass);
+ encodeHeaderFacets(context, writer, table.columns(),
"rich-table-subheadercell", headerClass, "header", "th",
columns);
+ writer.endElement("tr");
+ }
+ writer.endElement("thead");
+ }
+ }
+
+ public void encodeFooter(FacesContext context, UIDataTable table, int columns) throws
IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ Iterator<UIComponent> tableColumns = table.columns();
+
+ UIComponent footer = table.getFooter();
+ boolean columnFacetPresent = isColumnFacetPresent(table,"footer");
+
+ if (footer != null || columnFacetPresent) {
+ writer.startElement("tfoot", table);
+ String footerClass = (String) table.getAttributes().get("footerClass");
+
+ if (columnFacetPresent) {
+ writer.startElement("tr", table);
+ encodeStyleClass(writer, null, "rich-table-subfooter", null, footerClass);
+ encodeHeaderFacets(context, writer, tableColumns,
"rich-table-subfootercell", footerClass, "footer",
"td",columns);
+ writer.endElement("tr");
+ }
+
+ if (footer != null) {
+ encodeTableHeaderFacet(context, columns, writer, footer,
+ "rich-table-footer",
+ "rich-table-footer-continue",
+ "rich-table-footercell",
+ footerClass, "td");
+ }
+ writer.endElement("tfoot");
+ }
+ }
+
+ protected int getColumnsCount(UIDataTable table) {
+ int count = 0;
+ // check for exact value in component
+ Integer span = (Integer) table.getAttributes().get("columns");
+ if (null != span && span.intValue() != Integer.MIN_VALUE) {
+ count = span.intValue();
+ } else {
+ // calculate max html columns count for all columns/rows children.
+ Iterator<UIComponent> col = table.columns();
+ count = calculateRowColumns(col);
+ }
+ return count;
+ }
+
+ protected int calculateRowColumns(Iterator<UIComponent> col) {
+ int count = 0;
+ int currentLength = 0;
+ while (col.hasNext()) {
+ UIComponent component = (UIComponent) col.next();
+ if (component.isRendered()) {
+ if (component instanceof Row) {
+ // Store max calculated value of previsous rows.
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ // Calculate number of columns in row.
+ currentLength = calculateRowColumns(((Row) component).columns());
+ // Store max calculated value
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ currentLength = 0;
+ } else if (component instanceof Column) {
+ Column column = (Column) component;
+ // For new row, save length of previsous.
+ if (column.isBreakBefore()) {
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ currentLength = 0;
+ }
+ Integer colspan = (Integer) component.getAttributes().get("colspan");
+ // Append colspan of this column
+ if (null != colspan && colspan.intValue() != Integer.MIN_VALUE) {
+ currentLength += colspan.intValue();
+ } else {
+ currentLength++;
+ }
+ } else if (component instanceof UIColumn) {
+ // UIColumn always have colspan == 1.
+ currentLength++;
+ }
+ }
+ }
+
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ return count;
+ }
+
+ @Override
+ public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
+ encodeTBody(context, (UIDataTable) component);
+ }
+
+ public void encodeTBody (FacesContext context, UIDataTable table) throws IOException {
+ String clientId = table.getClientId(context);
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement("tbody", table);
+ writer.writeAttribute("id", clientId + ":tb", null);
+ encodeRows(context, table);
+ writer.endElement("tbody");
+ }
+
+ @Override
+ public void encodeOneRow(FacesContext context, TableHolder holder) throws IOException {
+
+ UIDataTable table = (UIDataTable) holder.getTable();
+ ResponseWriter writer = context.getResponseWriter();
+ Iterator<UIComponent> iter = table.columns();
+
+ boolean firstColumn = true;
+ boolean firstRow = (holder.getRowCounter() == 0);
+
+ int currentColumn = 0;
+ UIComponent column = null;
+ while (iter.hasNext()) {
+ column = (UIComponent) iter.next();
+ // Start new row for first column - expect a case of the detail
+ // table, wich will be insert own row.
+ if (firstColumn && !(column instanceof Row)) {
+ String rowSkinClass = getRowSkinClass();
+ if (firstRow) {
+ String firstRowSkinClass = getFirstRowSkinClass();
+ if (firstRowSkinClass != null && firstRowSkinClass.length() != 0) {
+
+ if (rowSkinClass != null && rowSkinClass.length() != 0) {
+ rowSkinClass += " " + firstRowSkinClass;
+ } else {
+ rowSkinClass = firstRowSkinClass;
+ }
+
+ }
+ }
+
+ encodeRowStart(context, rowSkinClass, holder.getRowClass(), table, writer);
+ }
+ if (column instanceof Column) {
+ boolean breakBefore = ((Column) column).isBreakBefore()
+ || column instanceof Row;
+ if (breakBefore && !firstColumn) {
+ // close current row
+ writer.endElement(HTML.TR_ELEMENT);
+ // reset columns counter.
+ currentColumn = 0;
+ // Start new row, expect a case of the detail table, wich
+ // will be insert own row.
+ if (!(column instanceof Row)) {
+ holder.nextRow();
+ encodeRowStart(context, holder.getRowClass(), table, writer);
+ }
+ }
+
+ encodeCellChildren(context, column,
+ firstRow ? getFirstRowSkinClass() : null,
+ getRowSkinClass(), holder.getRowClass(),
+ getCellSkinClass(), holder.getColumnClass(currentColumn));
+ // renderChild(context, column);
+ if ((column instanceof Row) && iter.hasNext()) {
+ // Start new row for remained columns.
+ holder.nextRow();
+ encodeRowStart(context, holder.getRowClass(), table, writer);
+ // reset columns counter.
+ currentColumn = -1;
+ }
+ } else if (column.isRendered()) {
+ // UIColumn don't have own renderer
+ writer.startElement(HTML.td_ELEM, table);
+ getUtils().encodeId(context, column);
+ String columnClass = holder.getColumnClass(currentColumn);
+ encodeStyleClass(writer, null, getCellSkinClass(), null, columnClass);
+
+ // TODO - encode column attributes.
+ renderChildren(context, column);
+ writer.endElement(HTML.td_ELEM);
+ }
+ currentColumn++;
+ firstColumn = false;
+ }
+ // Close row if then is open.
+ if (!firstColumn && !(column instanceof Row)) {
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+ }
+
+ protected void encodeRowStart(FacesContext context, String rowClass, UIDataTable table,
ResponseWriter writer) throws IOException {
+ encodeRowStart(context, getRowSkinClass(), rowClass, table, writer);
+ }
+
+
+ /**
+ * @return
+ */
+ protected String getRowSkinClass() {
+ return "rich-table-row";
+ }
+
+ /**
+ * @return
+ */
+ protected String getFirstRowSkinClass() {
+ return "rich-table-firstrow";
+ }
+
+ /**
+ * @return
+ */
+ protected String getCellSkinClass() {
+ return "rich-table-cell";
+ }
+
+ protected void encodeRowStart(FacesContext context, String skinClass, String rowClass,
UIDataTable table, ResponseWriter writer) throws IOException {
+ writer.startElement(HTML.TR_ELEMENT, table);
+ encodeStyleClass(writer, null, skinClass, null, rowClass);
+ encodeRowEvents(context, table);
+ }
+
+// private void encodeRowStart(ResponseWriter writer, UIColumn column) throws IOException
{
+// writer.startElement(HTML.td_ELEM, column);
+// }
+//
+// private void encodeRowEnd(ResponseWriter writer, UIColumn column) throws IOException
{
+// writer.endElement(HTML.td_ELEM);
+// }
+//
+// private void encodeRow(FacesContext facesContext, ResponseWriter writer, UIColumn
column) throws IOException {
+// renderChildren(facesContext, column);
+// }
+
+ protected class SimpleHeaderEncodeStrategy implements HeaderEncodeStrategy {
+
+ public void encodeBegin(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn)
+ throws IOException {
+
+ }
+
+ public void encodeEnd(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn)
+ throws IOException {
+
+ }
+ }
+
+ // will be changed
+ protected class RichHeaderEncodeStrategy implements HeaderEncodeStrategy {
+
+ public void encodeBegin(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn)
+ throws IOException {
+
+ }
+
+ public void encodeEnd(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn)
+ throws IOException {
+
+ }
+ }
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/TableHolder.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/TableHolder.java 2009-10-16
17:19:51 UTC (rev 15719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/TableHolder.java 2009-10-19
09:10:58 UTC (rev 15720)
@@ -24,6 +24,7 @@
import java.util.Map;
import org.richfaces.component.UIDataAdaptor;
+import org.richfaces.component.UIDataTable;
/**
* Private class for keep reference to table and intermediate iteration values ( current
row styles, events etc )
@@ -31,7 +32,7 @@
*
*/
public class TableHolder {
- private UIDataAdaptor table;
+ private UIDataTable table;
private int rowCounter;
private int gridRowCounter;
private String[] rowClasses;
@@ -40,7 +41,7 @@
/**
* @param table
*/
- public TableHolder(UIDataAdaptor table) {
+ public TableHolder(UIDataTable table) {
this.table = table;
this.rowCounter = 0;
this.gridRowCounter = 0;