[richfaces-svn-commits] JBoss Rich Faces SVN: r4435 - in branches/3.1.x/ui/orderingList/src/main: java/org/richfaces/component and 4 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Tue Dec 4 00:21:55 EST 2007
Author: nbelaevski
Date: 2007-12-04 00:21:55 -0500 (Tue, 04 Dec 2007)
New Revision: 4435
Removed:
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/OrderingBaseAbstractSubmittedValue.java
Modified:
branches/3.1.x/ui/orderingList/src/main/config/component/orderinglist.xml
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/model/OrderingListDataModel.java
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingComponentRendererBase.java
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/ListBase.js
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/SelectItem.js
branches/3.1.x/ui/orderingList/src/main/templates/org/richfaces/htmlOrderingList.jspx
Log:
latest changes for listShuttle & orderingList
Modified: branches/3.1.x/ui/orderingList/src/main/config/component/orderinglist.xml
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/config/component/orderinglist.xml 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/config/component/orderinglist.xml 2007-12-04 05:21:55 UTC (rev 4435)
@@ -178,9 +178,6 @@
<property hidden="true" el="false">
<name>submittedValue</name>
</property>
- <property hidden="true" el="false" exist="true">
- <name>submittedString</name>
- </property>
<property hidden="true" el="false">
<name>localValueSet</name>
</property>
Deleted: branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/OrderingBaseAbstractSubmittedValue.java
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/OrderingBaseAbstractSubmittedValue.java 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/OrderingBaseAbstractSubmittedValue.java 2007-12-04 05:21:55 UTC (rev 4435)
@@ -1,114 +0,0 @@
-/**
- *
- */
-package org.richfaces.component;
-
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.faces.FacesException;
-
-/**
- * @author Nick Belaevski
- *
- */
-abstract class OrderingBaseAbstractSubmittedValue implements Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = -6779511867226722256L;
-
- private Set selection = new HashSet();
-
- private Set activeItems = new HashSet();
-
- protected abstract Object createOldKey(String keyString);
-
- protected abstract Object createNewKey(int i);
-
- protected abstract Pattern getKeyStringPattern();
-
- protected Set getActiveItems() {
- return activeItems;
- }
-
- protected Set getSelection() {
- return selection;
- }
-
- protected Map asMap(String string) {
- if (string != null && string.length() != 0) {
- String substring = string.trim().substring(1, string.length() - 1);
-
- String[] valueOrder = substring.split(",");
- Map translationMap = new LinkedHashMap(valueOrder.length);
- for (int i = 0; i < valueOrder.length; i++) {
- if (valueOrder[i].length() == 0) {
- continue;
- }
-
- Matcher matcher = getKeyStringPattern().matcher(valueOrder[i]);
- if (matcher.matches()) {
- Object oldKey = createOldKey(matcher.group(1));
- Object newKey = createNewKey(i);
- translationMap.put(oldKey, newKey);
- String group = matcher.group(2);
- for (int j = 0; j < group.length(); j++) {
- char c = group.charAt(j);
- if ('s' == c) {
- selection.add(oldKey);
- } else if ('a' == c) {
- activeItems.add(oldKey);
- } else {
- break ;
- }
- }
- } else {
- throw new FacesException(new IllegalArgumentException());
- }
- }
-
- return translationMap;
- } else {
-
- return null;
- }
- }
-
- protected String asString(Map map) {
- if (map != null) {
- StringBuffer result = new StringBuffer();
- Iterator iterator = map.entrySet().iterator();
- while (iterator.hasNext()) {
- Entry entry = (Entry) iterator.next();
-
- Object key = entry.getKey();
-
- result.append(key);
- if (selection.contains(key)) {
- result.append('s');
- }
-
- if (activeItems.contains(key)) {
- result.append('a');
- }
-
- if (iterator.hasNext()) {
- result.append(',');
- }
- }
- return "[" + result.toString() + "]";
- } else {
- return "";
- }
- }
-
-}
Modified: branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2007-12-04 05:21:55 UTC (rev 4435)
@@ -3,18 +3,14 @@
*/
package org.richfaces.component;
-import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
@@ -34,7 +30,6 @@
import org.ajax4jsf.component.UIDataAdaptor;
import org.ajax4jsf.model.DataComponentState;
-import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.RepeatState;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.EmptyIterator;
@@ -51,12 +46,9 @@
private Object value;
private boolean localValueSet;
- private Collection selection;
- private boolean selectionSet;
+ protected Object activeItem;
+ protected boolean activeItemSet;
- private Object activeItem;
- private boolean activeItemSet;
-
private List validators = null;
private MethodBinding validator;
@@ -88,9 +80,6 @@
private Object value;
- private Collection selection;
- private boolean selectionSet;
-
private Object activeItem;
private boolean activeItemSet;
@@ -147,10 +136,8 @@
}
}
- public abstract Object getTranslatedRowKey();
-
public Object saveState(FacesContext faces) {
- Object[] state = new Object[9];
+ Object[] state = new Object[5];
state[0] = super.saveState(faces);
@@ -159,42 +146,7 @@
state[3] = this.value;
state[4] = localValueSet ? Boolean.TRUE : Boolean.FALSE;
-
- final HashSet selectionKeySet = new HashSet();
- final HashSet activeItemSet = new HashSet(1);
-
- Object rowKey = getRowKey();
- try {
- walk(faces, new DataVisitor() {
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- setRowKey(context, rowKey);
- Object data = getRowData();
- if (data.equals(activeItem)) {
- activeItemSet.add(getTranslatedRowKey());
- }
-
- if (selection != null && selection.contains(data)) {
- selectionKeySet.add(getTranslatedRowKey());
- }
-
- }
-
- }, null);
- } catch (IOException e) {
- throw new FacesException(e.getLocalizedMessage(), e);
- }
-
- setRowKey(rowKey);
-
- state[5] = selectionKeySet;
- state[6] = this.selectionSet ? Boolean.TRUE : Boolean.FALSE;
-
- state[7] = activeItemSet.isEmpty() ? null : activeItemSet.iterator().next();
- state[8] = this.activeItemSet ? Boolean.TRUE : Boolean.FALSE;
-
return state;
}
@@ -209,11 +161,6 @@
value = state[3];
localValueSet = ((Boolean) state[4]).booleanValue();
- this.selection = (Collection) state[5];
- this.selectionSet = ((Boolean) state[6]).booleanValue();
-
- this.activeItem = state[7];
- this.activeItemSet = ((Boolean) state[8]).booleanValue();
}
protected DataComponentState createComponentState() {
@@ -286,9 +233,7 @@
public Object getLocalValue() {
ValueHolder holder = new ValueHolder();
holder.value = this.value;
- holder.selection = this.selection;
- holder.selectionSet = this.selectionSet;
-
+
holder.activeItem = this.activeItem;
holder.activeItemSet = this.activeItemSet;
@@ -304,9 +249,6 @@
setValue(holder.value);
restoreIterationState(holder.state);
- this.selection = holder.selection;
- this.selectionSet = holder.selectionSet;
-
this.activeItem = holder.activeItem;
this.activeItemSet = holder.activeItemSet;
} else {
@@ -389,8 +331,6 @@
return;
}
- convertState(context);
-
super.processDecodes(context);
if (isImmediate()) {
@@ -509,21 +449,6 @@
};
- protected final UpdateModelCommand updateSelectionCommand = new UpdateModelCommand() {
-
- public void execute(FacesContext context) {
- if (selectionSet) {
- ValueBinding vb = getValueBinding("selection");
- if (vb != null) {
- vb.setValue(context, selection);
- selection = null;
- selectionSet = false;
- }
- }
- }
-
- };
-
protected final UpdateModelCommand updateActiveItemCommand = new UpdateModelCommand() {
public void execute(FacesContext context) {
@@ -635,24 +560,6 @@
return (false);
}
- public Collection getSelection() {
- if (this.selection != null) {
- return this.selection;
- } else {
- ValueBinding vb = getValueBinding("selection");
- if (vb != null) {
- return (Collection) vb.getValue(FacesContext.getCurrentInstance());
- }
- }
-
- return null;
- }
-
- public void setSelection(Collection collection) {
- this.selection = collection;
- this.selectionSet = true;
- }
-
public Object getActiveItem() {
if (this.activeItem != null) {
return this.activeItem;
@@ -671,98 +578,15 @@
this.activeItemSet = true;
}
- private void convertState(FacesContext faces) {
- Object rowKey = getRowKey();
-
- final HashSet selectionItemsSet = new HashSet();
- try {
- walk(faces, new DataVisitor() {
-
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- setRowKey(context, rowKey);
-
- if (selection != null && selection.contains(rowKey)) {
- selectionItemsSet.add(getRowData());
- }
-
- if (rowKey.equals(activeItem)) {
- activeItem = getRowData();
- }
- }
-
- }, null);
- } catch (IOException e) {
- throw new FacesException(e.getLocalizedMessage(), e);
- }
-
- if (this.selection != null) {
- this.selection = selectionItemsSet;
- }
-
- setRowKey(rowKey);
- }
-
- protected Set[] convertKeySets(FacesContext context, Set[] sets) {
- Set[] result = new Set[sets.length];
-
- for (int i = 0; i < sets.length; i++) {
- Set set = result[i] = new HashSet();
-
- Iterator iterator = sets[i].iterator();
- while (iterator.hasNext()) {
- setRowKey(context, iterator.next());
- set.add(getRowData());
- }
- }
-
- return result;
- }
-
- protected DataAdder createDataAdder(Object object, int size) {
- if (object instanceof List) {
- return new ListDataAdder(size);
+ protected Object createContainer(ArrayList data, Class objectClass) {
+ if (objectClass.isArray()) {
+ return data.toArray((Object[]) Array.newInstance(objectClass.getComponentType(), data.size()));
} else {
- return new ArrayDataAdder(object.getClass(), size);
+ data.trimToSize();
+ return data;
}
}
- private class ListDataAdder implements DataAdder {
- private ArrayList container;
-
- public ListDataAdder(int size) {
- container = new ArrayList(size);
- }
-
- public Object getContainer() {
- container.trimToSize();
- return container;
- }
-
- public void add(Object object) {
- container.add(object);
- }
- }
-
- private class ArrayDataAdder implements DataAdder {
- private int idx = 0;
- private Object[] objects;
-
- public ArrayDataAdder(Class objectClass, int size) {
- this.objects = (Object[]) Array.newInstance(objectClass.getComponentType(),
- size);
- }
-
- public void add(Object object) {
- this.objects[idx++] = object;
- }
-
- public Object getContainer() {
- return objects;
- }
- }
-
public abstract ItemState getItemState();
public interface ItemState {
@@ -770,23 +594,31 @@
public boolean isActive();
}
- protected final class SubmittedItemState implements ItemState {
+// protected final class SubmittedItemState implements ItemState {
+//
+// private Object activeItem;
+// private Set selectionKeys;
+//
+// public boolean isActive() {
+// return activeItemKeys != null && activeItemKeys.contains(getRowKey());
+// }
+//
+// public boolean isSelected() {
+// return selectionKeys != null && selectionKeys.contains(getRowKey());
+// }
+//
+// public SubmittedItemState(Set selectionKeys, Set activeItemKeys) {
+// super();
+// this.selectionKeys = selectionKeys;
+// this.activeItemKeys = activeItemKeys;
+// }
+// }
+
+ protected Object getAsObject(String string) {
+ return string;
+ }
- private Set activeItemKeys;
- private Set selectionKeys;
-
- public boolean isActive() {
- return activeItemKeys != null && activeItemKeys.contains(getRowKey());
- }
-
- public boolean isSelected() {
- return selectionKeys != null && selectionKeys.contains(getRowKey());
- }
-
- public SubmittedItemState(Set selectionKeys, Set activeItemKeys) {
- super();
- this.selectionKeys = selectionKeys;
- this.activeItemKeys = activeItemKeys;
- }
+ protected String getAsString(Object object) {
+ return object.toString();
}
}
Modified: branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java 2007-12-04 05:21:55 UTC (rev 4435)
@@ -1,11 +1,13 @@
package org.richfaces.component;
import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Pattern;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
@@ -28,51 +30,55 @@
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.SequenceDataModel;
import org.richfaces.model.OrderingListDataModel;
public abstract class UIOrderingList extends UIOrderingBaseComponent {
- private transient Map permutationOrder;
+ public UIOrderingList() {
+ super();
- protected static final class SubmittedValue extends OrderingBaseAbstractSubmittedValue {
- private static final Pattern KEY_STRING_PATTERN = Pattern.compile("(\\d+)(s?a?)");
+ final ComponentVisitor decodeVisitor = this.decodeVisitor;
- /**
- *
- */
- private static final long serialVersionUID = 5860506816451180551L;
- private Map permutationOrder;
+ this.decodeVisitor = new ComponentVisitor() {
- public SubmittedValue(String submittedString) {
- super();
+ public void processComponent(FacesContext context, UIComponent c,
+ Object argument) throws IOException {
- permutationOrder = asMap(submittedString);
-
- if (getActiveItems().size() > 1) {
- throw new FacesException(new IllegalArgumentException());
+ if (UIOrderingList.this.submittedValueHolder != null) {
+ //TODO check for item existence
+ }
+
+ decodeVisitor.processComponent(context, c, argument);
}
- }
- public String toString() {
- return asString(permutationOrder);
- }
+ };
+ }
+
+ protected void processDecodes(FacesContext faces, Object argument) {
+ if (!this.isRendered())
+ return;
+ this.decode(faces);
+ this.iterate(faces, decodeVisitor, argument);
+ }
- protected Object createNewKey(int i) {
- return new Integer(i);
- }
+ private transient Map dataMap;
- protected Object createOldKey(String keyString) {
- try {
- return new Integer(keyString);
- } catch (NumberFormatException e) {
- throw new FacesException(e.getLocalizedMessage(), e);
- }
+ protected static final class SubmittedValue implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5860506816451180551L;
+
+ private Map dataMap;
+ private Collection selection;
+ private Object activeItem;
+
+ public SubmittedValue(Map dataMap, Set selection, Object activeItem) {
+ this.dataMap = dataMap;
+ this.selection = selection;
+ this.activeItem = activeItem;
}
-
- protected Pattern getKeyStringPattern() {
- return KEY_STRING_PATTERN;
- }
-
}
private final class ModelItemState implements ItemState {
@@ -95,17 +101,42 @@
}
protected ExtendedDataModel createDataModel() {
- DataModel dataModel = createDataModel(getValue());
+ Map modelMap = null;
- if (isTranslatedRenderingState() || isTranslatedState()) {
- return new OrderingListDataModel(dataModel, isTranslatedState(), submittedValueHolder != null ? submittedValueHolder.permutationOrder : this.permutationOrder);
+ if (submittedValueHolder != null) {
+ modelMap = submittedValueHolder.dataMap;
} else {
- return new OrderingListDataModel(dataModel, false, null);
+ modelMap = this.dataMap;
}
+
+ if (modelMap != null) {
+ OrderingListDataModel dataModel = new OrderingListDataModel();
+ dataModel.setWrappedData(modelMap);
+ return dataModel;
+ } else {
+ DataModel dataModel = createDataModel(getValue());
+ return new SequenceDataModel(dataModel);
+ }
}
private transient SubmittedValue submittedValueHolder = null;
+
+ protected static final class ValueHolder implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4216115242421460529L;
+
+ private Collection selection;
+ private boolean selectionSet;
+
+ private Map map;
+ }
+
+ private Collection selection;
+ private boolean selectionSet;
+
public void addValueChangeListener(ValueChangeListener listener) {
addFacesListener(listener);
}
@@ -128,15 +159,10 @@
removeFacesListener(listener);
}
-
- public String getSubmittedString() {
- return submittedValueHolder != null ? submittedValueHolder.toString() : "";
+ public void setSubmittedString(Map submittedString, Set selection, Object activeItem) {
+ this.submittedValueHolder = new SubmittedValue(submittedString, selection, activeItem);
}
- public void setSubmittedString(String submittedString) {
- this.submittedValueHolder = new SubmittedValue(submittedString);
- }
-
protected Object saveIterationSubmittedState() {
return submittedValueHolder;
}
@@ -146,11 +172,18 @@
}
protected Object saveIterationState() {
- return permutationOrder;
+ ValueHolder valueHolder = new ValueHolder();
+ valueHolder.map = dataMap;
+ valueHolder.selection = selection;
+ valueHolder.selectionSet = selectionSet;
+ return valueHolder;
}
protected void restoreIterationState(Object object) {
- this.permutationOrder = (Map) object;
+ ValueHolder valueHolder = (ValueHolder) object;
+ dataMap = valueHolder.map;
+ selection = valueHolder.selection;
+ selectionSet = valueHolder.selectionSet;
}
public abstract void setImmediate(boolean immediate);
@@ -187,7 +220,6 @@
}
super.processDecodes(context);
-
}
/**
@@ -273,8 +305,23 @@
}
+ protected final UpdateModelCommand updateSelectionCommand = new UpdateModelCommand() {
+
+ public void execute(FacesContext context) {
+ if (selectionSet) {
+ ValueBinding vb = getValueBinding("selection");
+ if (vb != null) {
+ vb.setValue(context, selection);
+ selection = null;
+ selectionSet = false;
+ }
+ }
+ }
+
+ };
+
/**
- * <p>Perform the following algorithm to update the model data
+ * <p>Perform the following algorithm to update the model dataMap
* associated with this {@link UIInput}, if any, as appropriate.</p>
* <ul>
* <li>If the <code>valid</code> property of this component is
@@ -333,7 +380,7 @@
* indicates that no value was submitted for this component.)</li>
*
* <li> Convert the submitted value into a "local value" of the
- * appropriate data type by calling {@link #getConvertedValue}.</li>
+ * appropriate dataMap type by calling {@link #getConvertedValue}.</li>
*
* <li>Validate the property by calling {@link #validateValue}.</li>
*
@@ -379,22 +426,21 @@
}
OrderingListDataModel dataModel = (OrderingListDataModel) getExtendedDataModel();
- dataModel.setTranslationTable(submittedValueHolder.permutationOrder);
try {
- final DataAdder dataAdder = createDataAdder(previousValue, dataModel.getRowCount());
+ final ArrayList list = new ArrayList(dataModel.getRowCount());
walk(context, new DataVisitor() {
public void process(FacesContext context, Object rowKey,
Object argument) throws IOException {
- setRowKey(rowKey);
- dataAdder.add(getRowData());
+ setRowKey(context, rowKey);
+ list.add(getRowData());
}
}, null);
- newValue = dataAdder.getContainer();
+ newValue = createContainer(list, previousValue.getClass());
} catch (IOException e) {
throw new ConverterException(e.getLocalizedMessage(), e);
}
@@ -410,19 +456,9 @@
// If our value is valid, store the new value, erase the
// "submitted" value, and emit a ValueChangeEvent if appropriate
if (isValid()) {
- Set[] sets = convertKeySets(context,
- new Set[] {
- submittedValueHolder.getSelection(),
- submittedValueHolder.getActiveItems() });
+ setSelection(submittedValueHolder.selection);
- setSelection(sets[0]);
-
- Set activeItems = sets[1];
- if (activeItems.isEmpty()) {
- setActiveItem(null);
- } else {
- setActiveItem(activeItems.iterator().next());
- }
+ setActiveItem(submittedValueHolder.activeItem);
setValue(newValue);
setTranslatedState();
@@ -431,7 +467,7 @@
queueEvent(new ValueChangeEvent(this, previousValue, newValue));
}
- this.permutationOrder = this.submittedValueHolder.permutationOrder;
+ this.dataMap = this.submittedValueHolder.dataMap;
this.submittedValueHolder = null;
}
}
@@ -439,7 +475,7 @@
protected void resetDataModel() {
super.resetDataModel();
- this.permutationOrder = null;
+ this.dataMap = null;
if (this.submittedValueHolder != null) {
setTranslatedRenderingState();
@@ -536,26 +572,88 @@
}
}
- public Object getTranslatedRowKey() {
- return ((OrderingListDataModel) getExtendedDataModel()).getTranslatedRowKey();
- }
-
public ItemState getItemState() {
if (submittedValueHolder != null) {
- return new SubmittedItemState(submittedValueHolder.getSelection(),
- submittedValueHolder.getActiveItems());
+ return new ModelItemState(submittedValueHolder.selection,
+ submittedValueHolder.activeItem);
} else {
return new ModelItemState(getSelection(), getActiveItem());
}
}
- /*public abstract boolean isOrderControlsVisible();
- public abstract void setOrderControlsVisible(boolean visible);
-
- public abstract boolean isFastOrderControlsVisible();
- public abstract void setFastOrderControlsVisible(boolean visible);*/
-
public abstract String getControlsType();
public abstract void setControlsType(String type);
+ public Collection getSelection() {
+ if (this.selection != null) {
+ return this.selection;
+ } else {
+ ValueBinding vb = getValueBinding("selection");
+ if (vb != null) {
+ return (Collection) vb.getValue(FacesContext.getCurrentInstance());
+ }
+ }
+
+ return null;
+ }
+
+ public void setSelection(Collection collection) {
+ this.selection = collection;
+ this.selectionSet = true;
+ }
+
+ public Object saveState(FacesContext faces) {
+ Object[] state = new Object[5];
+ state[0] = super.saveState(faces);
+
+ Object rowKey = getRowKey();
+
+ final HashSet selectionKeySet = new HashSet();
+ final HashSet activeItemSet = new HashSet(1);
+ try {
+ walk(faces, new DataVisitor() {
+
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+
+ setRowKey(context, rowKey);
+ Object data = getRowData();
+
+ if (data != null) {
+ if (data.equals(activeItem)) {
+ activeItemSet.add(rowKey);
+ }
+
+ if (selection != null && selection.contains(data)) {
+ selectionKeySet.add(rowKey);
+ }
+ }
+ }
+
+ }, null);
+ } catch (IOException e) {
+ throw new FacesException(e.getLocalizedMessage(), e);
+ }
+
+ state[1] = selectionKeySet;
+ state[2] = this.selectionSet ? Boolean.TRUE : Boolean.FALSE;
+
+ state[3] = activeItemSet.isEmpty() ? null : activeItemSet.iterator().next();
+ state[4] = this.activeItemSet ? Boolean.TRUE : Boolean.FALSE;
+
+ return state;
+ }
+
+ public void restoreState(FacesContext faces, Object object) {
+ Object[] state = (Object[]) object;
+
+ super.restoreState(faces, state[0]);
+
+ this.selection = (Collection) state[1];
+ this.selectionSet = ((Boolean) state[2]).booleanValue();
+
+ this.activeItem = state[3];
+ this.activeItemSet = ((Boolean) state[4]).booleanValue();
+ }
+
}
Modified: branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/model/OrderingListDataModel.java
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/model/OrderingListDataModel.java 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/model/OrderingListDataModel.java 2007-12-04 05:21:55 UTC (rev 4435)
@@ -4,17 +4,15 @@
package org.richfaces.model;
import java.io.IOException;
-import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
-import java.util.Map.Entry;
+import java.util.Set;
import javax.faces.context.FacesContext;
-import javax.faces.model.DataModel;
import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
-import org.ajax4jsf.model.SequenceDataModel;
/**
* @author Nick Belaevski
@@ -22,114 +20,62 @@
* created 07.11.2007
*
*/
-public class OrderingListDataModel extends SequenceDataModel {
+public class OrderingListDataModel extends ExtendedDataModel {
- protected static final class TranslatedRowKey implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = -2035943770925539333L;
- private Object key;
- private String asString;
-
- public TranslatedRowKey(Object key, String asString) {
- super();
- this.key = key;
- this.asString = asString;
- }
-
- public Object getKey() {
- return key;
- }
-
- public String getAsString() {
- return asString;
- }
-
- public String toString() {
- return getAsString();
- }
- };
+ private Map data;
- private Map translationTable;
- private boolean translatedModel;
-
private Object rowKey;
- public OrderingListDataModel(DataModel wrapped,
- boolean translatedModel, Map translationTable) {
- super(wrapped);
- this.translatedModel = translatedModel;
- this.translationTable = translationTable;
+ public Object getRowKey() {
+ return rowKey;
}
- public OrderingListDataModel(DataModel wrapped) {
- super(wrapped);
+ public void setRowKey(Object rowKey) {
+ this.rowKey = rowKey;
}
- private Object translate(Object key) {
- if (translationTable != null) {
- return translationTable.get(key);
- } else {
- return key;
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+
+ Set entrySet = data.entrySet();
+ Iterator iterator = entrySet.iterator();
+
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+
+ visitor.process(context, entry.getKey(), argument);
}
}
-
- public Object getTranslatedRowKey() {
- return super.getRowKey();
+
+ public int getRowCount() {
+ return data.size();
}
-
- public Object getRowKey() {
- return rowKey;
+
+ public Object getRowData() {
+ return data.get(rowKey);
}
-
- public void setRowKey(Object key) {
- this.rowKey = key;
- if (key instanceof TranslatedRowKey) {
- super.setRowKey(((TranslatedRowKey) key).getKey());
- } else {
- if (this.translatedModel) {
- if (rowKey != null) {
- super.setRowKey(translate(key));
- } else {
- super.setRowKey(null);
- }
- } else {
- super.setRowKey(key);
- }
- }
+ public int getRowIndex() {
+ // TODO Auto-generated method stub
+ return 0;
}
-
- public void walk(FacesContext context, DataVisitor visitor, Range range,
- Object argument) throws IOException {
- if (this.translationTable != null) {
- Iterator iterator = this.translationTable.entrySet().iterator();
- while (iterator.hasNext()) {
- Entry entry = (Entry) iterator.next();
-
- if (this.translatedModel) {
- visitor.process(context, new TranslatedRowKey(
- entry.getValue(), String.valueOf(entry.getKey())), argument);
- } else {
- visitor.process(context, entry.getKey(), argument);
- }
- }
- } else {
- for (int i = 0; i < getRowCount(); i++) {
- if (this.translatedModel) {
- Integer key = new Integer(i);
- visitor.process(context, new TranslatedRowKey(
- translate(key), String.valueOf(key)), argument);
- } else {
- visitor.process(context, new Integer(i), argument);
- }
- }
- }
+ public Object getWrappedData() {
+ return data;
}
-
- public void setTranslationTable(Map translationTable) {
- this.translationTable = translationTable;
+
+ public boolean isRowAvailable() {
+ return data.containsKey(rowKey);
}
+
+ public void setRowIndex(int rowIndex) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setWrappedData(Object data) {
+ this.rowKey = null;
+ this.data = (Map) data;
+ }
+
}
Modified: branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingComponentRendererBase.java
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingComponentRendererBase.java 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingComponentRendererBase.java 2007-12-04 05:21:55 UTC (rev 4435)
@@ -14,6 +14,7 @@
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import javax.faces.convert.Converter;
import org.ajax4jsf.renderkit.ComponentVariables;
import org.ajax4jsf.renderkit.ComponentsVariableResolver;
@@ -422,4 +423,21 @@
throws IOException {
return (ItemState) variables.getVariable(ITEM_STATE_VAR_NAME);
}
+
+ protected String getAsString(FacesContext context, UIOrderingBaseComponent component, Object object) {
+ if (object instanceof String) {
+ return (String) object;
+ }
+
+ return component.getConverter().getAsString(context, component, object);
+ }
+
+ protected Object getAsObject(FacesContext context, UIOrderingBaseComponent component, String string) {
+ Converter converter = component.getConverter();
+ if (converter != null) {
+ return converter.getAsObject(context, component, string);
+ } else {
+ return string;
+ }
+ }
}
Modified: branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java 2007-12-04 05:21:55 UTC (rev 4435)
@@ -1,12 +1,17 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@@ -107,6 +112,8 @@
writer.writeAttribute("class", rowClassName.toString(), null);
+ boolean columnRendered = false;
+
List children = table.getChildren();
for (Iterator iterator = children.iterator(); iterator.hasNext();) {
UIComponent component = (UIComponent) iterator.next();
@@ -121,6 +128,33 @@
}
writer.writeAttribute("class", cellClassName.toString(), null);
renderChildren(context, column);
+
+ if (!columnRendered) {
+ writer.startElement(HTML.INPUT_ELEM, table);
+ writer.writeAttribute(HTML.id_ATTRIBUTE, clientId + "StateInput", null);
+ writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
+ writer.writeAttribute(HTML.NAME_ATTRIBUTE, table.getBaseClientId(context), null);
+
+ StringBuffer value = new StringBuffer();
+ value.append(table.getRowKey());
+
+ if (selected) {
+ value.append('s');
+ }
+
+ if (active) {
+ value.append('a');
+ }
+
+ value.append(':');
+ value.append(getAsString(context, table, table.getRowData()));
+
+ writer.writeAttribute(HTML.value_ATTRIBUTE, value.toString(), null);
+
+ writer.endElement(HTML.INPUT_ELEM);
+
+ columnRendered = true;
+ }
writer.endElement(HTML.td_ELEM);
}
@@ -132,14 +166,42 @@
public void doDecode(FacesContext context, UIComponent component) {
UIOrderingList orderingList = (UIOrderingList) component;
- String clientId = component.getClientId(context);
- Map requestParameterMap = context.getExternalContext()
+ String clientId = orderingList.getBaseClientId(context);
+ ExternalContext externalContext = context.getExternalContext();
+ Map requestParameterMap = externalContext
.getRequestParameterMap();
- String valueOrder = (String) requestParameterMap.get(clientId);
-
- if (valueOrder != null && valueOrder.length() != 0) {
- orderingList.setSubmittedString(valueOrder);
+ if (requestParameterMap.containsKey(clientId)) {
+ Set selection = new HashSet();
+ Object activeItem = null;
+ String[] strings = (String[]) externalContext.getRequestParameterValuesMap().get(clientId);
+ Map map = new LinkedHashMap();
+ for (int i = 0; i < strings.length; i++) {
+ String string = strings[i];
+ int idx = string.indexOf(':');
+ Object value = getAsObject(context, orderingList, string.substring(idx + 1));
+ String substring = string.substring(0, idx);
+
+ idx = substring.length() - 1;
+
+ if (substring.charAt(idx) == 'a') {
+ activeItem = value;
+ idx--;
+ }
+
+ if (substring.charAt(idx) == 's') {
+ selection.add(value);
+ idx--;
+ }
+
+ substring = substring.substring(0, idx + 1);
+
+ Object key = new Integer(substring);
+ map.put(key, value);
+ }
+ orderingList.setSubmittedString(map, selection, activeItem);
+ } else {
+ orderingList.setSubmittedString(new HashMap(0), null, null);
}
}
}
Modified: branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/ListBase.js
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/ListBase.js 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/ListBase.js 2007-12-04 05:21:55 UTC (rev 4435)
@@ -32,7 +32,7 @@
Richfaces.ListBase.CONTROL_SET = ["A", "INPUT", "TEXTAREA", "SELECT", "OPTION", "BUTTON"];
Richfaces.ListBase.prototype = {
- initialize : function(containerId, contentTableId, headerTableId, focusKeeperId, valueKeeperId,
+ initialize : function(containerId, contentTableId, headerTableId, focusKeeperId,
onclickControlId) {
this.selectedItems = new Array();
@@ -40,7 +40,6 @@
this.container = $(containerId);
this.shuttleTable = $(contentTableId);
Richfaces.disableSelectionText(this.shuttleTable);
- this.valueKeeper = $(valueKeeperId);
this.focusKeeper = $(focusKeeperId);
this.focusKeeper.focused = false;
//this.setFocus();
@@ -383,28 +382,25 @@
return false;
},
- getAsString : function() {
- var result = new Array();
+ saveState : function() {
for (var i = 0; i < this.shuttleItems.length; i++) {
var item = this.shuttleItems[i];
- result.push(item._id);
+ var value = item.input.value;
+
+ var idx = value.indexOf(":");
+ var state = value.substring(0, idx);
+ state = state.replace(/[as]/g, "");
+
+ //TODO optimization
if (Richfaces.SelectItems.isSelected(item._node)) {
- result.push(Richfaces.OrderingList.SELECTION_MARKER);
+ state = state + "s";
}
if (this.activeItem && (this.activeItem.rowIndex == item._node.rowIndex)) {
- result.push(Richfaces.OrderingList.ACTIVITY_MARKER);
+ state = state + "a";
}
- if (i != (this.shuttleItems.length - 1)) {
- result.push(Richfaces.OrderingList.ITEM_SEPARATOR);
- }
+
+ item.input.value = state + value.substring(idx);
}
- return result.join("");
- },
-
- saveState : function() {
- //if (this.activeItem != null || (this.selectedItems.length > 0)) {
- this.valueKeeper.value = "[" + this.getAsString() + "]";
- //}
}
}
Modified: branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js 2007-12-04 05:21:55 UTC (rev 4435)
@@ -6,9 +6,9 @@
parent: Richfaces.ListBase
},
- initialize: function(containerId, contentTableId, headerTableId, focusKeeperId, valueKeeperId,
+ initialize: function(containerId, contentTableId, headerTableId, focusKeeperId,
ids, onclickControlId, onorderchanged) {
- Richfaces.OrderingList.parentClass.constructor().call(this, containerId, contentTableId, headerTableId, focusKeeperId, valueKeeperId, onclickControlId);
+ Richfaces.OrderingList.parentClass.constructor().call(this, containerId, contentTableId, headerTableId, focusKeeperId, onclickControlId);
this.onorderchanged = onorderchanged;
this.controlList = new Array();
Modified: branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/SelectItem.js
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/SelectItem.js 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/SelectItem.js 2007-12-04 05:21:55 UTC (rev 4435)
@@ -84,5 +84,8 @@
this._node.item = this;
this._id = id;
this._selected = selected;
+
+ //TODO 2 optimize
+ this.input = $(node.id + "StateInput");
}
}
Modified: branches/3.1.x/ui/orderingList/src/main/templates/org/richfaces/htmlOrderingList.jspx
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/templates/org/richfaces/htmlOrderingList.jspx 2007-12-04 05:21:42 UTC (rev 4434)
+++ branches/3.1.x/ui/orderingList/src/main/templates/org/richfaces/htmlOrderingList.jspx 2007-12-04 05:21:55 UTC (rev 4435)
@@ -31,7 +31,6 @@
<div id="#{clientId}" class="rich-ordering-list-ds" x:passThruWithExclusions="id,class">
<input id="#{clientId}focusKeeper" type="button" value="" name="focusKeeper"
style="width: 1px; position: absolute; left: -32767px;" />
- <input id="#{clientId}valueKeeper" type="hidden" name="#{clientId}" value="#{component.submittedString}"/>
<table id="#{clientId}table" cellpadding="0" cellspacing="0" class="rich-ordering-list-body">
<tbody>
@@ -90,7 +89,7 @@
var clientId = '#{cId}';
Event.onReady(function() {
var cotrolsIdPrefix = [['up', 'disup'], ['down', 'disdown'], ['last', 'dislast'], ['first','disfirst']];
- var shuttle = new Richfaces.OrderingList('#{cId}', '#{cId}internal_tab', '#{cId}internal_header_tab', '#{cId}focusKeeper', '#{cId}valueKeeper', cotrolsIdPrefix, '#{cId}sortLabel', function() {#{component.attributes['onorderchanged']}});
+ var shuttle = new Richfaces.OrderingList('#{cId}', '#{cId}internal_tab', '#{cId}internal_header_tab', '#{cId}focusKeeper', cotrolsIdPrefix, '#{cId}sortLabel', function() {#{component.attributes['onorderchanged']}});
var layoutManager = new LayoutManager('#{clientId}internal_header_tab', '#{clientId}internal_tab');
layoutManager.widthSynchronization();
});
More information about the richfaces-svn-commits
mailing list