Author: nbelaevski
Date: 2011-02-24 12:18:45 -0500 (Thu, 24 Feb 2011)
New Revision: 21925
Added:
branches/4.0.0.CR1/ui/common/ui/src/main/java/org/richfaces/StateHolderList.java
Modified:
branches/4.0.0.CR1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractCollapsibleSubTable.java
Log:
Added: branches/4.0.0.CR1/ui/common/ui/src/main/java/org/richfaces/StateHolderList.java
===================================================================
--- branches/4.0.0.CR1/ui/common/ui/src/main/java/org/richfaces/StateHolderList.java
(rev 0)
+++
branches/4.0.0.CR1/ui/common/ui/src/main/java/org/richfaces/StateHolderList.java 2011-02-24
17:18:45 UTC (rev 21925)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class StateHolderList extends AbstractList<Object> implements StateHolder {
+
+ private boolean tranzient = false;
+
+ private ArrayList<Object> backingList = Lists.newArrayListWithCapacity(2);
+
+ public Object saveState(FacesContext context) {
+ Object[] savedState = new Object[backingList.size()];
+
+ boolean hasNonNullState = false;
+
+ for (int i = 0; i < savedState.length; i++) {
+ Object state = UIComponentBase.saveAttachedState(context,
backingList.get(i));
+ savedState[i] = state;
+
+ if (state != null) {
+ hasNonNullState = true;
+ }
+ }
+
+ if (hasNonNullState) {
+ return savedState;
+ } else {
+ return null;
+ }
+ }
+
+ public void restoreState(FacesContext context, Object stateObject) {
+ if (stateObject != null) {
+ Object[] state = (Object[]) stateObject;
+
+ backingList.ensureCapacity(state.length);
+
+ for (int i = 0; i < state.length; i++) {
+ backingList.add(UIComponentBase.restoreAttachedState(context,
state[i]));
+ }
+ }
+ }
+
+ public boolean isTransient() {
+ return tranzient;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ this.tranzient = newTransientValue;
+ }
+
+ public boolean contains(Object o) {
+ return backingList.contains(o);
+ }
+
+ public Iterator<Object> iterator() {
+ return backingList.iterator();
+ }
+
+ public boolean add(Object e) {
+ return backingList.add(e);
+ }
+
+ public boolean remove(Object o) {
+ return backingList.remove(o);
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return backingList.containsAll(c);
+ }
+
+ public boolean addAll(Collection<? extends Object> c) {
+ return backingList.addAll(c);
+ }
+
+ public boolean addAll(int index, Collection<? extends Object> c) {
+ return backingList.addAll(index, c);
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ return backingList.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c) {
+ return backingList.retainAll(c);
+ }
+
+ public void clear() {
+ backingList.clear();
+ }
+
+ public Object set(int index, Object element) {
+ return backingList.set(index, element);
+ }
+
+ public void add(int index, Object element) {
+ backingList.add(index, element);
+ }
+
+ public Object remove(int index) {
+ return backingList.remove(index);
+ }
+
+ public int indexOf(Object o) {
+ return backingList.indexOf(o);
+ }
+
+ public int lastIndexOf(Object o) {
+ return backingList.lastIndexOf(o);
+ }
+
+ public ListIterator<Object> listIterator() {
+ return backingList.listIterator();
+ }
+
+ public ListIterator<Object> listIterator(int index) {
+ return backingList.listIterator(index);
+ }
+
+ public List<Object> subList(int fromIndex, int toIndex) {
+ return backingList.subList(fromIndex, toIndex);
+ }
+
+ @Override
+ public Object get(int index) {
+ return backingList.get(index);
+ }
+
+ @Override
+ public int size() {
+ return backingList.size();
+ }
+
+}
Modified:
branches/4.0.0.CR1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractCollapsibleSubTable.java
===================================================================
---
branches/4.0.0.CR1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractCollapsibleSubTable.java 2011-02-24
16:54:18 UTC (rev 21924)
+++
branches/4.0.0.CR1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractCollapsibleSubTable.java 2011-02-24
17:18:45 UTC (rev 21925)
@@ -28,6 +28,7 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
+import org.richfaces.StateHolderList;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
@@ -141,10 +142,11 @@
}
public void setIterationState(Object stateObject) {
- Object[] state = (Object[]) stateObject;
- if (state != null) {
- super.setIterationState(state[0]);
- getStateHelper().put(PropertyKeys.expanded, state[1]);
+ StateHolderList stateHolderList = (StateHolderList) stateObject;
+
+ if (stateHolderList != null && !stateHolderList.isEmpty()) {
+ super.setIterationState(stateHolderList.get(0));
+ getStateHelper().put(PropertyKeys.expanded, (Boolean)
stateHolderList.get(1));
} else {
super.setIterationState(null);
getStateHelper().put(PropertyKeys.expanded, null);
@@ -152,9 +154,11 @@
}
public Object getIterationState() {
- Object [] state = new Object[2];
- state[0] = super.getIterationState();
- state[1] = getStateHelper().get(PropertyKeys.expanded);
- return state;
+ StateHolderList holderList = new StateHolderList();
+
+ holderList.add(super.getIterationState());
+ holderList.add(getStateHelper().get(PropertyKeys.expanded));
+
+ return holderList;
}
}
\ No newline at end of file