Author: nbelaevski
Date: 2011-01-21 08:46:25 -0500 (Fri, 21 Jan 2011)
New Revision: 21149
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/StatefulDataTableChildrenIterator.java
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
Log:
https://issues.jboss.org/browse/RF-9426
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/StatefulDataTableChildrenIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/StatefulDataTableChildrenIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/StatefulDataTableChildrenIterator.java 2011-01-21
13:46:25 UTC (rev 21149)
@@ -0,0 +1,67 @@
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+import org.ajax4jsf.component.IterationStateHolder;
+
+import com.google.common.collect.AbstractIterator;
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class StatefulDataTableChildrenIterator extends AbstractIterator<UIComponent>
{
+
+ private Iterator<UIComponent> dataChildren;
+
+ private Iterator<UIComponent> subIterator = Iterators.emptyIterator();
+
+ /**
+ * @param uiDataTableBase
+ */
+ StatefulDataTableChildrenIterator(Iterator<UIComponent> dataChildren) {
+ this.dataChildren = dataChildren;
+ }
+
+ private UIComponent traverseToNextElement() {
+ if (dataChildren.hasNext()) {
+ UIComponent c = dataChildren.next();
+
+ if (c instanceof IterationStateHolder) {
+ return c;
+ } else {
+ subIterator = c.getFacetsAndChildren();
+ }
+ }
+
+ return null;
+ }
+
+ private UIComponent traverseToNextSubElement() {
+ if (subIterator.hasNext()) {
+ return subIterator.next();
+ }
+
+ return null;
+ }
+
+ @Override
+ protected UIComponent computeNext() {
+ while (dataChildren.hasNext() || subIterator.hasNext()) {
+ UIComponent c = traverseToNextSubElement();
+
+ if (c == null) {
+ c = traverseToNextElement();
+ }
+
+ if (c != null) {
+ return c;
+ }
+ }
+
+ return endOfData();
+ }
+}
\ No newline at end of file
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2011-01-21
13:36:56 UTC (rev 21148)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2011-01-21
13:46:25 UTC (rev 21149)
@@ -62,6 +62,7 @@
import org.richfaces.model.SortMode;
import org.richfaces.renderkit.MetaComponentRenderer;
+
public abstract class UIDataTableBase extends UISequence implements Row,
MetaComponentResolver, MetaComponentEncoder {
public static final String COMPONENT_FAMILY = "org.richfaces.Data";
@@ -369,5 +370,27 @@
public static Set<String> getSupportedMetaComponents() {
return SUPPORTED_META_COMPONENTS;
}
-
+
+ protected Iterator<UIComponent> statefulChildren() {
+ return new StatefulDataTableChildrenIterator(this.dataChildren());
+ }
+
+ @Override
+ protected void saveChildState(FacesContext facesContext) {
+ Iterator<UIComponent> iterator = statefulChildren();
+ while (iterator.hasNext()) {
+ UIComponent c = iterator.next();
+ saveChildState(facesContext, c);
+ }
+ }
+
+ @Override
+ protected void restoreChildState(FacesContext facesContext) {
+ Iterator<UIComponent> iterator = statefulChildren();
+ while (iterator.hasNext()) {
+ UIComponent c = iterator.next();
+ restoreChildState(facesContext, c);
+ }
+ }
+
}