Author: nbelaevski
Date: 2007-11-16 15:44:08 -0500 (Fri, 16 Nov 2007)
New Revision: 4057
Added:
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
Modified:
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java
Log:
Latest changes for orderingList
Added:
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
===================================================================
---
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
(rev 0)
+++
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2007-11-16
20:44:08 UTC (rev 4057)
@@ -0,0 +1,239 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.ValueBinding;
+import javax.faces.validator.Validator;
+
+import org.ajax4jsf.component.UIDataAdaptor;
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.RepeatState;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.iterators.EmptyIterator;
+import org.apache.commons.collections.iterators.FilterIterator;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 16.11.2007
+ * @since 3.2
+ */
+public abstract class UIOrderingBaseComponent extends UIDataAdaptor implements
EditableValueHolder {
+
+ private Object value;
+ private boolean localValueSet;
+
+ private List validators = null;
+ private MethodBinding validator;
+
+ public static final Predicate isColumn = new Predicate() {
+ public boolean evaluate(Object input) {
+ return (input instanceof UIColumn || input instanceof Column) &&
+ ((UIComponent) input).isRendered();
+ }
+ };
+
+
+ private static class EditableState {
+ private boolean translated = false;
+
+ //setting this flag to true means we should reorder elements
+ private boolean translatedRendering = false;
+ }
+
+ private static final class ValueHolder {
+ private Object value;
+ private Object state;
+ }
+
+ private transient EditableState editableState = new EditableState();
+
+ protected abstract void restoreIterationState(Object object);
+ protected abstract Object saveIterationState();
+
+ protected abstract void restoreIterationSubmittedState(Object object);
+ protected abstract Object saveIterationSubmittedState();
+
+ protected void setTranslatedState() {
+ this.editableState.translated = true;
+ }
+
+ protected boolean isTranslatedState() {
+ return this.editableState.translated;
+ }
+
+ protected void setTranslatedRenderingState() {
+ this.editableState.translatedRendering = true;
+ }
+
+ protected boolean isTranslatedRenderingState() {
+ return this.editableState.translatedRendering;
+ }
+
+ public final Object getSubmittedValue() {
+ Object[] state = new Object[2];
+
+ state[0] = saveIterationSubmittedState();
+ state[1] = editableState;
+
+ return state;
+ }
+
+ public final void setSubmittedValue(Object object) {
+ if (object != null) {
+ Object[] state = (Object[]) object;
+
+ restoreIterationSubmittedState(state[0]);
+ editableState = (EditableState) state[1];
+ } else {
+ restoreIterationSubmittedState(null);
+ }
+ }
+
+ public Object saveState(FacesContext faces) {
+ Object[] state = new Object[6];
+
+ state[0] = super.saveState(faces);
+ state[1] = saveIterationState();
+
+ state[2] = saveAttachedState(faces, validators);
+ state[3] = saveAttachedState(faces, validator);
+
+ state[4] = this.value;
+ state[5] = localValueSet ? Boolean.TRUE : Boolean.FALSE;
+
+ return state;
+ }
+
+ public void restoreState(FacesContext faces, Object object) {
+ Object[] state = (Object[]) object;
+
+ super.restoreState(faces, state[0]);
+ restoreIterationState(state[1]);
+
+ validators = (List) restoreAttachedState(faces, state[2]);
+ validator = (MethodBinding) restoreAttachedState(faces, state[3]);
+
+ value = state[4];
+ localValueSet = ((Boolean) state[5]).booleanValue();
+ }
+
+ protected DataComponentState createComponentState() {
+ return new RepeatState();
+ }
+
+ public Iterator columns() {
+ return new FilterIterator(getChildren().iterator(), isColumn);
+ }
+
+ protected Iterator dataChildren() {
+ if (getChildCount() != 0) {
+ return columns();
+ } else {
+ return EmptyIterator.INSTANCE;
+ }
+ }
+
+ protected Iterator fixedChildren() {
+ if (getFacetCount() != 0) {
+ return getFacets().values().iterator();
+ } else {
+ return EmptyIterator.INSTANCE;
+ }
+ }
+
+ //validators
+ public MethodBinding getValidator() {
+ return validator;
+ }
+
+ public void setValidator(MethodBinding validatorBinding) {
+ this.validator = validatorBinding;
+ }
+
+ public Validator[] getValidators() {
+
+ if (validators == null) {
+ return new Validator[0];
+ } else {
+ return (Validator[]) validators.toArray(new Validator[validators.size()]);
+ }
+ }
+
+ public void addValidator(Validator validator) {
+ if (validator == null) {
+ throw new NullPointerException();
+ }
+
+ if (validators == null) {
+ validators = new ArrayList();
+ }
+
+ validators.add(validator);
+ }
+
+ public void removeValidator(Validator validator) {
+ if (validators != null) {
+ validators.remove(validator);
+ }
+ }
+ //validators end
+
+ //value
+ protected Object getLocalValueFieldValue() {
+ return value;
+ }
+
+ public Object getLocalValue() {
+ ValueHolder valueHolder = new ValueHolder();
+ valueHolder.value = this.value;
+ valueHolder.state = saveIterationState();
+
+ return valueHolder;
+ }
+
+ public void setValue(Object value) {
+ if (value instanceof ValueHolder) {
+ ValueHolder holder = (ValueHolder) value;
+
+ setValue(holder.value);
+ restoreIterationState(holder.state);
+ } else {
+ super.setValue(value);
+ this.value = value;
+ setLocalValueSet(true);
+ }
+ }
+
+ public Object getValue() {
+ if (this.value != null) {
+ return (this.value);
+ }
+ ValueBinding ve = getValueBinding("value");
+ if (ve != null) {
+ return (ve.getValue(getFacesContext()));
+ } else {
+ return (null);
+ }
+ }
+ //value end
+
+ public boolean isLocalValueSet() {
+ return localValueSet;
+ }
+
+ public void setLocalValueSet(boolean localValueSet) {
+ this.localValueSet = localValueSet;
+ }
+
+}
Modified:
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
===================================================================
---
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java 2007-11-16
20:25:49 UTC (rev 4056)
+++
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java 2007-11-16
20:44:08 UTC (rev 4057)
@@ -15,8 +15,6 @@
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIInput;
@@ -30,34 +28,17 @@
import javax.faces.event.FacesEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;
-import javax.faces.model.ArrayDataModel;
import javax.faces.model.DataModel;
-import javax.faces.model.ListDataModel;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
-import org.ajax4jsf.component.UIDataAdaptor;
import org.ajax4jsf.javascript.ScriptUtils;
-import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.RepeatState;
-import org.apache.commons.collections.Predicate;
-import org.apache.commons.collections.iterators.EmptyIterator;
-import org.apache.commons.collections.iterators.FilterIterator;
-public abstract class UIOrderingList extends UIDataAdaptor implements EditableValueHolder
{
+public abstract class UIOrderingList extends UIOrderingBaseComponent {
- protected static class EditableState {
- private boolean isTranslated = false;
-
- //setting this flag to true means we should reorder elements
- private boolean translatedRendering = false;
- }
-
public static final class ValueHolder {
- private Object value;
-
private Collection selection;
private boolean selectionSet;
@@ -130,72 +111,66 @@
}
- public static final Predicate isColumn = new Predicate() {
- public boolean evaluate(Object input) {
- return (input instanceof UIColumn || input instanceof Column) &&
- ((UIComponent) input).isRendered();
+ public interface ItemState {
+ public boolean isSelected();
+ public boolean isActive();
+ }
+
+ private final class SubmittedItemState implements ItemState {
+ private Collection selectedItemsKeys;
+ private Object activeItemKey;
+
+ public SubmittedItemState(Collection selectedItemsKeys, Integer activeItemKey) {
+ super();
+ this.selectedItemsKeys = selectedItemsKeys;
+ this.activeItemKey = activeItemKey;
}
- };
- protected DataComponentState createComponentState() {
- return new RepeatState();
+ public boolean isActive() {
+ return activeItemKey != null && activeItemKey.equals(getTranslatedRowKey());
+ }
+
+ public boolean isSelected() {
+ return selectedItemsKeys != null &&
selectedItemsKeys.contains(getTranslatedRowKey());
+ }
}
+
+ private final class CommonItemState implements ItemState {
+ private Collection selectedItems;
+ private Object activeItem;
+
+ public CommonItemState(Collection selectedItems, Object activeItem) {
+ super();
+ this.selectedItems = selectedItems;
+ this.activeItem = activeItem;
+ }
- protected DataModel getDataModel(Object current) {
- if (current == null) {
- return new ListDataModel(Collections.EMPTY_LIST);
- } else if (current instanceof List) {
- return new ListDataModel((List) current);
- } else if (Object[].class.isAssignableFrom(current.getClass())) {
- //TODO scalar
- return new ArrayDataModel((Object[]) current);
- }
- throw new IllegalArgumentException();
- }
+ public boolean isSelected() {
+ return selectedItems != null && selectedItems.contains(getRowData());
+ }
+
+ public boolean isActive() {
+ return activeItem != null && activeItem.equals(getRowData());
+ }
+ }
protected ExtendedDataModel createDataModel() {
DataModel dataModel = super.getDataModel();
- if (editableState.translatedRendering || editableState.isTranslated) {
- return new TranslatedSequenceDataModel(dataModel, editableState.isTranslated,
submittedValueHolder != null ? submittedValueHolder.permutationOrder : null);
+ if (isTranslatedRenderingState() || isTranslatedState()) {
+ return new TranslatedSequenceDataModel(dataModel, isTranslatedState(),
submittedValueHolder != null ? submittedValueHolder.permutationOrder : null);
} else {
return new TranslatedSequenceDataModel(dataModel, false, null);
}
}
- protected Iterator dataChildren() {
- if (getChildCount() != 0) {
- return getChildren().iterator();
- } else {
- return EmptyIterator.INSTANCE;
- }
- }
- protected Iterator fixedChildren() {
- if (getFacetCount() != 0) {
- return getFacets().values().iterator();
- } else {
- return EmptyIterator.INSTANCE;
- }
- }
-
- public Iterator columns() {
- return new FilterIterator(getChildren().iterator(), isColumn);
- }
-
- private List validators = null;
- private MethodBinding validator;
-
- private Object value;
- private boolean localValueSet;
-
- private Collection selection;
+ private Collection localSelection;
private boolean localSelectionSet;
- private Object activeItem;
+ private Object localActiveItem;
private boolean localActiveItemSet;
private transient SubmittedValue submittedValueHolder = null;
- private transient EditableState editableState = new EditableState();
private void convertState(FacesContext faces) {
final HashSet selectionItemsSet = new HashSet();
@@ -208,12 +183,12 @@
dataModel.setRowKey(rowKey);
- if (selection != null && selection.contains(rowKey)) {
+ if (localSelection != null && localSelection.contains(rowKey)) {
selectionItemsSet.add(getRowData());
}
- if (rowKey.equals(activeItem)) {
- activeItem = getRowData();
+ if (rowKey.equals(localActiveItem)) {
+ localActiveItem = getRowData();
}
}
@@ -223,39 +198,29 @@
e.printStackTrace();
}
- if (this.selection != null) {
- this.selection = selectionItemsSet;
+ if (this.localSelection != null) {
+ this.localSelection = selectionItemsSet;
}
}
public void restoreState(FacesContext faces, Object object) {
final Object[] state = (Object[]) object;
super.restoreState(faces, state[0]);
- validators = (List) restoreAttachedState(faces, state[1]);
- validator = (MethodBinding) restoreAttachedState(faces, state[2]);
- value = state[3];
- localValueSet = ((Boolean) state[4]).booleanValue();
-
- localSelectionSet = ((Boolean) state[5]).booleanValue();
- localActiveItemSet = ((Boolean) state[6]).booleanValue();
+ localSelectionSet = ((Boolean) state[3]).booleanValue();
+ localActiveItemSet = ((Boolean) state[4]).booleanValue();
- selection = (Collection) state[7];
- activeItem = state[8];
+ localSelection = (Collection) state[5];
+ localActiveItem = state[6];
}
public Object saveState(FacesContext faces) {
- Object[] state = new Object[9];
+ Object[] state = new Object[7];
state[0] = super.saveState(faces);
- state[1] = saveAttachedState(faces, validators);
- state[2] = saveAttachedState(faces, validator);
- state[3] = value;
- state[4] = localValueSet ? Boolean.TRUE : Boolean.FALSE;
+ state[3] = localSelectionSet ? Boolean.TRUE : Boolean.FALSE;
+ state[4] = localActiveItemSet ? Boolean.TRUE : Boolean.FALSE;
- state[5] = localSelectionSet ? Boolean.TRUE : Boolean.FALSE;
- state[6] = localActiveItemSet ? Boolean.TRUE : Boolean.FALSE;
-
final HashSet selectionKeySet = new HashSet();
final HashSet activeItemSet = new HashSet(1);
@@ -268,11 +233,11 @@
dataModel.setRowKey(rowKey);
Object data = dataModel.getRowData();
- if (data.equals(activeItem)) {
+ if (data.equals(localActiveItem)) {
activeItemSet.add(getTranslatedRowKey());
}
- if (selection != null && selection.contains(data)) {
+ if (localSelection != null && localSelection.contains(data)) {
selectionKeySet.add(getTranslatedRowKey());
}
@@ -284,41 +249,18 @@
e.printStackTrace();
}
- state[7] = selectionKeySet;
+ state[5] = selectionKeySet;
- state[8] = activeItemSet.isEmpty() ? null : activeItemSet.iterator().next();
+ state[6] = activeItemSet.isEmpty() ? null : activeItemSet.iterator().next();
return state;
}
- public void addValidator(Validator validator) {
- if (validator == null) {
- throw new NullPointerException();
- }
-
- if (validators == null) {
- validators = new ArrayList();
- }
-
- validators.add(validator);
- }
-
public void addValueChangeListener(ValueChangeListener listener) {
addFacesListener(listener);
}
- public MethodBinding getValidator() {
- return validator;
- }
- public Validator[] getValidators() {
- if (validators == null) {
- return new Validator[0];
- } else {
- return (Validator[]) validators.toArray(new Validator[validators.size()]);
- }
- }
-
public abstract MethodBinding getValueChangeListener();
public ValueChangeListener[] getValueChangeListeners() {
@@ -327,23 +269,10 @@
public abstract boolean isImmediate();
- public boolean isLocalValueSet() {
- return localValueSet;
- }
-
- public void setLocalValueSet(boolean localValueSet) {
- this.localValueSet = localValueSet;
- }
-
public abstract boolean isRequired();
public abstract boolean isValid();
- public void removeValidator(Validator validator) {
- if (validators != null) {
- validators.remove(validator);
- }
- }
public void removeValueChangeListener(ValueChangeListener listener) {
removeFacesListener(listener);
@@ -358,80 +287,48 @@
this.submittedValueHolder = new SubmittedValue(submittedString);
}
- public Object getSubmittedValue() {
- return new Object[] { submittedValueHolder, editableState };
+ protected Object saveIterationSubmittedState() {
+ return submittedValueHolder;
}
- public void setSubmittedValue(Object submittedValue) {
- if (submittedValue != null) {
- Object[] values = (Object[]) submittedValue;
-
- this.submittedValueHolder = (SubmittedValue) values[0];
- this.editableState = (EditableState) values[1];
- } else {
- this.submittedValueHolder = null;
- }
+ protected void restoreIterationSubmittedState(Object object) {
+ this.submittedValueHolder = (SubmittedValue) object;
}
+
+ protected Object saveIterationState() {
+ ValueHolder holder = new ValueHolder();
+ holder.selection = localSelection;
+ holder.selectionSet = localSelectionSet;
+
+ holder.activeItem = localActiveItem;
+ holder.activeItemSet = localActiveItemSet;
+
+ return holder;
+ }
+
+ protected void restoreIterationState(Object object) {
+ ValueHolder holder = (ValueHolder) object;
+
+ this.localSelection = holder.selection;
+ this.localSelectionSet = holder.selectionSet;
+
+ this.localActiveItem = holder.activeItem;
+ this.localActiveItemSet = holder.activeItemSet;
+ }
+
public abstract void setImmediate(boolean immediate);
public abstract void setRequired(boolean required);
public abstract void setValid(boolean valid);
- public void setValidator(MethodBinding validatorBinding) {
- this.validator = validatorBinding;
- }
-
public abstract void setValueChangeListener(MethodBinding valueChangeMethod);
public abstract Converter getConverter();
public abstract void setConverter(Converter converter);
-
- public Object getLocalValue() {
- ValueHolder holder = new ValueHolder();
- holder.value = value;
-
- holder.selection = selection;
- holder.selectionSet = localSelectionSet;
-
- holder.activeItem = activeItem;
- holder.activeItemSet = localActiveItemSet;
- return holder;
- }
-
- public void setValue(Object value) {
- if (value instanceof ValueHolder) {
- ValueHolder holder = (ValueHolder) value;
-
- setValue(holder.value);
-
- this.selection = holder.selection;
- this.localSelectionSet = holder.selectionSet;
-
- this.activeItem = holder.activeItem;
- this.localActiveItemSet = holder.activeItemSet;
- } else {
- super.setValue(value);
- this.value = value;
- setLocalValueSet(true);
- }
- }
-
- public Object getValue() {
- if (this.value != null) {
- return (this.value);
- }
- ValueBinding ve = getValueBinding("value");
- if (ve != null) {
- return (ve.getValue(getFacesContext()));
- } else {
- return (null);
- }
- }
-
/**
* <p>Specialized decode behavior on top of that provided by the
* superclass. In addition to the standard
@@ -583,8 +480,7 @@
if (isLocalValueSet()) {
ValueBinding vb = getValueBinding("value");
if (vb != null) {
- ValueHolder localValue = (ValueHolder) getLocalValue();
- vb.setValue(context, localValue.value);
+ vb.setValue(context, getLocalValueFieldValue());
setValue(null);
setLocalValueSet(false);
}
@@ -596,13 +492,12 @@
private final UpdateModelCommand updateSelectionCommand = new UpdateModelCommand() {
public void execute(FacesContext context) {
- ValueHolder localValue = (ValueHolder) getLocalValue();
- if (localValue.selectionSet) {
+ if (localSelectionSet) {
ValueBinding vb = getValueBinding("selection");
if (vb != null) {
- vb.setValue(context, localValue.selection);
- localValue.selection = null;
- localValue.selectionSet = false;
+ vb.setValue(context, localSelection);
+ localSelection = null;
+ localSelectionSet = false;
}
}
}
@@ -612,13 +507,12 @@
private final UpdateModelCommand updateActiveItemCommand = new UpdateModelCommand() {
public void execute(FacesContext context) {
- ValueHolder localValue = (ValueHolder) getLocalValue();
- if (localValue.activeItemSet) {
+ if (localActiveItemSet) {
ValueBinding vb = getValueBinding("activeItem");
if (vb != null) {
- vb.setValue(context, localValue.activeItem);
- localValue.activeItem = null;
- localValue.activeItemSet = false;
+ vb.setValue(context, localActiveItem);
+ localActiveItem = null;
+ localActiveItemSet = false;
}
}
}
@@ -800,7 +694,7 @@
Object previous = getValue();
setValue(newValue);
- this.editableState.isTranslated = true;
+ setTranslatedState();
//setSubmittedValue(null);
if (compareValues(previous, newValue)) {
queueEvent(new ValueChangeEvent(this, previous, newValue));
@@ -852,7 +746,7 @@
super.resetDataModel();
if (this.submittedValueHolder != null) {
- this.editableState.translatedRendering = true;
+ setTranslatedRenderingState();
}
}
@@ -900,25 +794,25 @@
// If our value is valid and not empty, call all validators
if (isValid() && !isEmpty(newValue)) {
- if (this.validators != null) {
- Iterator validators = this.validators.iterator();
- while (validators.hasNext()) {
- Validator validator = (Validator) validators.next();
- try {
- validator.validate(context, this, newValue);
+ Validator[] validators = getValidators();
+ for (int i = 0; i < validators.length; i++) {
+ Validator validator = (Validator) validators[i];
+ try {
+ validator.validate(context, this, newValue);
+ }
+ catch (ValidatorException ve) {
+ // If the validator throws an exception, we're
+ // invalid, and we need to add a message
+ setValid(false);
+ FacesMessage message = ve.getFacesMessage();
+ if (message != null) {
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(getClientId(context), message);
}
- catch (ValidatorException ve) {
- // If the validator throws an exception, we're
- // invalid, and we need to add a message
- setValid(false);
- FacesMessage message = ve.getFacesMessage();
- if (message != null) {
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- }
- }
}
}
+
+ MethodBinding validator = getValidator();
if (validator != null) {
try {
validator.invoke(context,
@@ -1030,7 +924,7 @@
public String getElementsOrder() {
Object order = null;
- if (this.editableState.translatedRendering) {
+ if (isTranslatedRenderingState()) {
if (this.submittedValueHolder != null) {
order = this.submittedValueHolder.permutationOrder;
}
@@ -1039,21 +933,21 @@
return ScriptUtils.toScript(order);
}
- public boolean isActive() {
- return activeItem != null && activeItem.equals(getRowData()) ||
submittedValueHolder != null && (submittedValueHolder.activeItem != null
&& submittedValueHolder.activeItem.equals(getTranslatedRowKey()));
- }
-
public int getModelSize() {
return getExtendedDataModel().getRowCount();
}
-
- public boolean isSelected() {
- return selection != null && selection.contains(getRowData()) ||
submittedValueHolder != null &&
submittedValueHolder.selectedItems.contains(getTranslatedRowKey());
+
+ public ItemState getItemState() {
+ if (submittedValueHolder != null) {
+ return new SubmittedItemState(submittedValueHolder.selectedItems,
submittedValueHolder.activeItem);
+ } else {
+ return new CommonItemState(getSelection(), getActiveItem());
+ }
}
public Collection getSelection() {
- if (this.selection != null) {
- return this.selection;
+ if (this.localSelection != null) {
+ return this.localSelection;
} else {
ValueBinding vb = getValueBinding("selection");
if (vb != null) {
@@ -1065,13 +959,13 @@
}
public void setSelection(Collection collection) {
- this.selection = collection;
+ this.localSelection = collection;
this.localSelectionSet = true;
}
public Object getActiveItem() {
- if (this.activeItem != null) {
- return this.activeItem;
+ if (this.localActiveItem != null) {
+ return this.localActiveItem;
} else {
ValueBinding vb = getValueBinding("activeItem");
if (vb != null) {
@@ -1083,7 +977,7 @@
}
public void setActiveItem(Object activeItem) {
- this.activeItem = activeItem;
+ this.localActiveItem = activeItem;
this.localActiveItemSet = true;
}
Modified:
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java
===================================================================
---
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java 2007-11-16
20:25:49 UTC (rev 4056)
+++
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java 2007-11-16
20:44:08 UTC (rev 4057)
@@ -18,6 +18,7 @@
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIOrderingList;
+import org.richfaces.component.UIOrderingList.ItemState;
import org.richfaces.renderkit.html.images.OrderingListIconBottom;
import org.richfaces.renderkit.html.images.OrderingListIconBottomDisabled;
import org.richfaces.renderkit.html.images.OrderingListIconDown;
@@ -315,6 +316,23 @@
writer.endElement("thead");
}
+ private static final ThreadLocal<ItemState> itemStates = new
ThreadLocal<ItemState>();
+
+ public void encodeBegin(FacesContext context, UIComponent component)
+ throws IOException {
+ itemStates.set(((UIOrderingList) component).getItemState());
+ super.encodeBegin(context, component);
+ }
+
+ public void encodeEnd(FacesContext context, UIComponent component)
+ throws IOException {
+ try {
+ super.encodeEnd(context, component);
+ } finally {
+ itemStates.set(null);
+ }
+ }
+
public void encodeControlsFacets(FacesContext context, UIOrderingList orderingList)
throws IOException {
String clientId = orderingList.getClientId(context);
@@ -325,10 +343,12 @@
boolean selectedLast = false;
try {
+ ItemState state = itemStates.get();
+
orderingList.setRowKey(new Integer(0));
- selectedFirst = orderingList.isSelected();
+ selectedFirst = state.isSelected();
orderingList.setRowKey(new Integer(orderingList.getModelSize() - 1));
- selectedLast = orderingList.isSelected();
+ selectedLast = state.isSelected();
} finally {
try {
orderingList.setRowKey(key);
@@ -523,12 +543,15 @@
StringBuffer rowClassName = new StringBuffer("ol_normal
rich-ordering-list-row");
StringBuffer cellClassName = new StringBuffer("ol_cell
rich-ordering-list-cell");
- if (table.isActive()) {
+
+ ItemState state = itemStates.get();
+
+ if (state.isActive()) {
rowClassName.append(" ol_active rich-ordering-list-row-active");
cellClassName.append(" rich-ordering-list-cell-active");
}
- if (table.isSelected()) {
+ if (state.isSelected()) {
rowClassName.append(" ol_select rich-ordering-list-row-selected");
cellClassName.append(" rich-ordering-list-cell-selected");
}