JBoss Rich Faces SVN: r4434 - in branches/3.1.x/samples/orderingListDemo/src/main: webapp/WEB-INF and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-12-04 00:21:42 -0500 (Tue, 04 Dec 2007)
New Revision: 4434
Added:
branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/OptionItemConverter.java
Modified:
branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/OptionItem.java
branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/UIEventsBouncer.java
branches/3.1.x/samples/orderingListDemo/src/main/webapp/WEB-INF/faces-config.xml
branches/3.1.x/samples/orderingListDemo/src/main/webapp/pages/index.jsp
Log:
latest changes for listShuttle & orderingList
Modified: branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/OptionItem.java
===================================================================
--- branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/OptionItem.java 2007-12-04 05:21:32 UTC (rev 4433)
+++ branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/OptionItem.java 2007-12-04 05:21:42 UTC (rev 4434)
@@ -36,4 +36,30 @@
return this.getClass().getSimpleName() + " [" + name + "] by " + price;
}
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + price;
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ OptionItem other = (OptionItem) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (price != other.price)
+ return false;
+ return true;
+ }
+
}
Added: branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/OptionItemConverter.java
===================================================================
--- branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/OptionItemConverter.java (rev 0)
+++ branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/OptionItemConverter.java 2007-12-04 05:21:42 UTC (rev 4434)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.richfaces;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+/**
+ * @author mikalaj
+ *
+ */
+public class OptionItemConverter implements Converter {
+
+ /* (non-Javadoc)
+ * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
+ */
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value) {
+
+ int index = value.indexOf(':');
+
+ return new OptionItem(value.substring(0, index), Integer.valueOf(value.substring(index + 1)));
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
+ */
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value) {
+
+ OptionItem optionItem = (OptionItem) value;
+ return optionItem.getName() + ":" + optionItem.getPrice();
+ }
+
+}
Modified: branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/UIEventsBouncer.java
===================================================================
--- branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/UIEventsBouncer.java 2007-12-04 05:21:32 UTC (rev 4433)
+++ branches/3.1.x/samples/orderingListDemo/src/main/java/org/richfaces/UIEventsBouncer.java 2007-12-04 05:21:42 UTC (rev 4434)
@@ -13,9 +13,10 @@
import javax.faces.event.PhaseId;
import org.ajax4jsf.component.UIDataAdaptor;
-import org.richfaces.component.UIOrderingList;
public final class UIEventsBouncer extends UIOutput {
+ private PhaseId phaseId;
+
final class Event extends FacesEvent {
/**
@@ -73,6 +74,8 @@
public void processDecodes(FacesContext context) {
super.processDecodes(context);
+ this.phaseId = PhaseId.APPLY_REQUEST_VALUES;
+
queueEvent(PhaseId.PROCESS_VALIDATIONS);
queueEvent(PhaseId.UPDATE_MODEL_VALUES);
queueEvent(PhaseId.INVOKE_APPLICATION);
@@ -81,12 +84,16 @@
public void processUpdates(FacesContext context) {
super.processUpdates(context);
+ this.phaseId = PhaseId.UPDATE_MODEL_VALUES;
+
queueEvent(PhaseId.INVOKE_APPLICATION);
}
public void processValidators(FacesContext context) {
super.processValidators(context);
+ this.phaseId = PhaseId.PROCESS_VALIDATIONS;
+
queueEvent(PhaseId.UPDATE_MODEL_VALUES);
queueEvent(PhaseId.INVOKE_APPLICATION);
}
@@ -97,6 +104,7 @@
String cid = getList().getClientId(FacesContext.getCurrentInstance());
if (!cid.equals(((Event) event).getClientId())) {
System.out.println(cid + " !!! " + ((Event) event).getClientId());
+ System.out.println(phaseId + " " + event.getPhaseId());
FacesMessage message = new FacesMessage("Client ids mismatch: " + cid + " !!! " + ((Event) event).getClientId());
message.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(cid, message);
@@ -107,6 +115,7 @@
Object rd = list.getRowData();
if (!rd.equals(((Event) event).getValue())) {
System.out.println(rd + " !!! " + ((Event) event).getValue());
+ System.out.println(phaseId + " " + event.getPhaseId());
FacesMessage message = new FacesMessage("Data mismatch: " + rd + " !!! " + ((Event) event).getValue());
message.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(cid, message);
Modified: branches/3.1.x/samples/orderingListDemo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- branches/3.1.x/samples/orderingListDemo/src/main/webapp/WEB-INF/faces-config.xml 2007-12-04 05:21:32 UTC (rev 4433)
+++ branches/3.1.x/samples/orderingListDemo/src/main/webapp/WEB-INF/faces-config.xml 2007-12-04 05:21:42 UTC (rev 4434)
@@ -21,4 +21,10 @@
<managed-bean-class>org.richfaces.SkinBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+
+ <managed-bean>
+ <managed-bean-name>converter</managed-bean-name>
+ <managed-bean-class>org.richfaces.OptionItemConverter</managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
+ </managed-bean>
</faces-config>
Modified: branches/3.1.x/samples/orderingListDemo/src/main/webapp/pages/index.jsp
===================================================================
--- branches/3.1.x/samples/orderingListDemo/src/main/webapp/pages/index.jsp 2007-12-04 05:21:32 UTC (rev 4433)
+++ branches/3.1.x/samples/orderingListDemo/src/main/webapp/pages/index.jsp 2007-12-04 05:21:42 UTC (rev 4434)
@@ -40,6 +40,7 @@
<h:panelGrid columns="2" columnClasses="columnClass">
<h:panelGroup>
<ol:orderingList id="orderingList1"
+ converter="#{converter}"
value="#{demoBean.items}" var="item"
captionLabel="#{demoBean.captionLabel}"
controlsType="#{demoBean.controlsType}"
@@ -186,7 +187,7 @@
<h:commandButton value="Clear list" action="#{demoBean.clear}"></h:commandButton>
<h:panelGrid columns="3" >
<a4j:repeat value="#{bean.lists}" var="list" id="repeat">
- <ol:orderingList value="#{list.items}" var="item" >
+ <ol:orderingList value="#{list.items}" var="item" converter="#{converter}">
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
16 years, 5 months
JBoss Rich Faces SVN: r4433 - in branches/3.1.x/ui/listShuttle/src/main: java/org/richfaces/component and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-12-04 00:21:32 -0500 (Tue, 04 Dec 2007)
New Revision: 4433
Modified:
branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml
branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java
branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleDataModel.java
branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleRowKey.java
branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java
branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx
Log:
latest changes for listShuttle & orderingList
Modified: branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml 2007-12-04 05:21:18 UTC (rev 4432)
+++ branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml 2007-12-04 05:21:32 UTC (rev 4433)
@@ -43,9 +43,6 @@
<property hidden="true" el="false">
<name>submittedValue</name>
</property>
- <property hidden="true" el="false" exist="true">
- <name>submittedStrings</name>
- </property>
<property hidden="true" el="false">
<name>localValueSet</name>
</property>
@@ -60,10 +57,6 @@
<property hidden="true">
<name>value</name>
</property>
- <property elonly="true">
- <name>selection</name>
- <description>Collection which stores a set of selected items</description>
- </property>
<property>
<name>switchByClick</name>
Modified: branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java 2007-12-04 05:21:18 UTC (rev 4432)
+++ branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java 2007-12-04 05:21:32 UTC (rev 4433)
@@ -6,12 +6,14 @@
import java.io.IOException;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Pattern;
import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
@@ -22,6 +24,7 @@
import javax.faces.model.DataModel;
import org.ajax4jsf.model.DataVisitor;
+import org.richfaces.component.UIOrderingBaseComponent.UpdateModelCommand;
import org.richfaces.model.ListShuttleDataModel;
import org.richfaces.model.ListShuttleRowKey;
@@ -35,104 +38,88 @@
public static final String COMPONENT_FAMILY = "org.richfaces.ListShuttle";
+ private Collection sourceSelection;
+ private boolean sourceSelectionSet;
+
+ private Collection targetSelection;
+ private boolean targetSelectionSet;
+
+ public UIListShuttle() {
+ super();
+
+ final ComponentVisitor decodeVisitor = this.decodeVisitor;
+
+ this.decodeVisitor = new ComponentVisitor() {
+
+ public void processComponent(FacesContext context, UIComponent c,
+ Object argument) throws IOException {
+
+ if (UIListShuttle.this.submittedValueHolder != null) {
+ //TODO check for item existence
+ }
+
+ decodeVisitor.processComponent(context, c, argument);
+ }
+
+ };
+ }
+
+ protected void processDecodes(FacesContext faces, Object argument) {
+ if (!this.isRendered())
+ return;
+ this.decode(faces);
+ this.iterate(faces, decodeVisitor, argument);
+ }
+
private final class ModelItemState implements ItemState {
- private Collection selectedItems;
+ private Collection sourceSelectedItems;
+ private Collection targetSelectedItems;
private Object activeItem;
- public ModelItemState(Collection selectedItems, Object activeItem) {
+ public ModelItemState(Collection sourceSelectedItems, Collection targetSelectedItems, Object activeItem) {
super();
- this.selectedItems = selectedItems;
+ this.sourceSelectedItems = sourceSelectedItems;
+ this.targetSelectedItems = targetSelectedItems;
this.activeItem = activeItem;
}
public boolean isSelected() {
- return selectedItems != null && selectedItems.contains(getRowData());
+ Object rowData = getRowData();
+ return ((sourceSelectedItems != null && sourceSelectedItems.contains(rowData)) ||
+ (targetSelectedItems != null && targetSelectedItems.contains(rowData)));
}
public boolean isActive() {
- return activeItem != null && ((Set) activeItem).contains(getRowData());
+ return activeItem != null && activeItem.equals(getRowData());
}
}
- protected static final class SubmittedValue extends OrderingBaseAbstractSubmittedValue {
- private static final Pattern KEY_STRING_PATTERN = Pattern.compile("((?:s|t)\\d+)(s?a?)");
+ protected static final class SubmittedValue implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5655312942714191981L;
//ListShuttleRowKey -> ListShuttleRowKey
- private Map sourceTranslationTable = null;
- private Map targetTranslationTable = null;
+ private Map map = null;
- private transient boolean source;
+ private Set sourceSelection;
+ private Set targetSelection;
+
+ private Object activeItem;
+
+ public SubmittedValue(Map map, Set sourceSelection, Set targetSelection, Object activeItem) {
+ this.map = map;
+
+ this.sourceSelection = sourceSelection;
+ this.targetSelection = targetSelection;
- public SubmittedValue(String[] submittedStrings) {
- super();
-
- source = true;
- sourceTranslationTable = asMap(submittedStrings[0]);
- source = false;
- targetTranslationTable = asMap(submittedStrings[1]);
+ this.activeItem = activeItem;
}
- public String toTargetString() {
- return asString(targetTranslationTable);
- }
-
- public String toSourceString() {
- return asString(sourceTranslationTable);
- }
-
- public Map getSourceTranslationTable() {
- return sourceTranslationTable;
- }
-
- public Map getTargetTranslationTable() {
- return targetTranslationTable;
- }
-
- protected Object createNewKey(int i) {
- return new ListShuttleRowKey(new Integer(i), source);
- }
-
- protected Object createOldKey(String keyString) {
- char c = keyString.charAt(0);
- boolean sourceKey = false;
- Integer integer;
-
- try {
- if (c == 's') {
- sourceKey = true;
- } else if (c == 't') {
- sourceKey = false;
- } else {
- throw new IllegalArgumentException();
- }
-
- integer = new Integer(keyString.substring(1));
- } catch (NumberFormatException e) {
- throw new FacesException(new IllegalArgumentException());
- }
-
- return new ListShuttleRowKey(integer, sourceKey, source);
- }
-
- protected Pattern getKeyStringPattern() {
- return KEY_STRING_PATTERN;
- }
}
- public String getSourceSubmittedString() {
- return submittedValueHolder != null ? submittedValueHolder.toSourceString() : "";
- }
+ private transient Map map;
- public String getTargetSubmittedString() {
- return submittedValueHolder != null ? submittedValueHolder.toTargetString() : "";
- }
-
- private transient Map sourceTranslationTable;
- private transient Map targetTranslationTable;
-
private transient SubmittedValue submittedValueHolder = null;
protected static final class ValueHolder implements Serializable {
@@ -147,8 +134,13 @@
private Object targetValue;
private boolean targetValueSet;
- private Map sourceTranslationTable;
- private Map targetTranslationTable;
+ private Collection sourceSelection;
+ private boolean sourceSelectionSet;
+
+ private Collection targetSelection;
+ private boolean targetSelectionSet;
+
+ private Map map;
}
private Object sourceValue;
@@ -158,11 +150,52 @@
private boolean targetValueSet;
public Object saveState(FacesContext context) {
- Object[] state = new Object[2];
+ Object[] state = new Object[8];
state[0] = super.saveState(context);
state[1] = saveIterationState();
+ final HashSet sourceSelectionKeySet = new HashSet();
+ final HashSet targetSelectionKeySet = new HashSet();
+ final HashSet activeItemSet = new HashSet(1);
+
+ Object rowKey = getRowKey();
+ try {
+ walk(context, 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 (sourceSelection != null && sourceSelection.contains(data)) {
+ sourceSelectionKeySet.add(rowKey);
+ } else if (targetSelection != null && targetSelection.contains(data)){
+ targetSelectionKeySet.add(rowKey);
+ }
+ }
+ }
+
+ }, null);
+ } catch (IOException e) {
+ throw new FacesException(e.getLocalizedMessage(), e);
+ }
+
+ state[2] = sourceSelectionKeySet;
+ state[3] = this.sourceSelectionSet ? Boolean.TRUE : Boolean.FALSE;
+
+ state[4] = targetSelectionKeySet;
+ state[5] = this.targetSelectionSet ? Boolean.TRUE : Boolean.FALSE;
+
+ state[6] = activeItemSet.isEmpty() ? null : activeItemSet.iterator().next();
+ state[7] = this.activeItemSet ? Boolean.TRUE : Boolean.FALSE;
+
return state;
}
@@ -171,6 +204,15 @@
super.restoreState(context, state[0]);
restoreIterationState(state[1]);
+
+ this.sourceSelection = (Collection) state[2];
+ this.sourceSelectionSet = ((Boolean) state[3]).booleanValue();
+
+ this.targetSelection = (Collection) state[4];
+ this.targetSelectionSet = ((Boolean) state[5]).booleanValue();
+
+ this.activeItem = state[6];
+ this.activeItemSet = ((Boolean) state[7]).booleanValue();
}
public Object getSourceValue() {
@@ -211,43 +253,8 @@
this.targetValueSet = true;
}
- public void setSubmittedStrings(String[] submittedStrings) {
- this.submittedValueHolder = new SubmittedValue(submittedStrings);
- final Map sourceTranslationTable = this.submittedValueHolder.getSourceTranslationTable();
- final Map targetTranslationTable = this.submittedValueHolder.getTargetTranslationTable();
-
- if (sourceTranslationTable != null && targetTranslationTable != null) {
- sourceTranslationTable.entrySet().removeAll(targetTranslationTable.entrySet());
- } else {
- ListShuttleDataModel dataModel = (ListShuttleDataModel) getExtendedDataModel();
- FacesContext context = FacesContext.getCurrentInstance();
-
- try {
- if (sourceTranslationTable != null) {
- dataModel.walkTarget(context, new DataVisitor() {
-
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- sourceTranslationTable.entrySet().remove(rowKey);
- }
-
- }, null, null);
- } else if (targetTranslationTable != null) {
- dataModel.walkSource(context, new DataVisitor() {
-
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- targetTranslationTable.entrySet().remove(rowKey);
- }
-
- }, null, null);
- }
- } catch (IOException e) {
- throw new FacesException(e.getLocalizedMessage(), e);
- }
- }
+ public void setSubmittedStrings(Map map, Set sourceSelection, Set targetSelection, Object activeItem) {
+ this.submittedValueHolder = new SubmittedValue(map, sourceSelection, targetSelection, activeItem);
}
protected Object saveIterationSubmittedState() {
@@ -267,48 +274,57 @@
holder.targetValue = targetValue;
holder.targetValueSet = targetValueSet;
- holder.sourceTranslationTable = sourceTranslationTable;
- holder.targetTranslationTable = targetTranslationTable;
+ holder.sourceSelection = this.sourceSelection;
+ holder.sourceSelectionSet = this.sourceSelectionSet;
+
+ holder.targetSelection = this.targetSelection;
+ holder.targetSelectionSet = this.targetSelectionSet;
+ holder.map = map;
+
return holder;
}
protected void restoreIterationState(Object object) {
ValueHolder holder = (ValueHolder) object;
- sourceValue = holder.sourceValue ;
- sourceValueSet = holder.sourceValueSet;
+ this.sourceValue = holder.sourceValue ;
+ this.sourceValueSet = holder.sourceValueSet;
- targetValue = holder.targetValue;
- targetValueSet = holder.targetValueSet;
+ this.targetValue = holder.targetValue;
+ this.targetValueSet = holder.targetValueSet;
- sourceTranslationTable = holder.sourceTranslationTable;
- targetTranslationTable = holder.targetTranslationTable;
+ this.sourceSelection = holder.sourceSelection;
+ this.sourceSelectionSet = holder.sourceSelectionSet;
+
+ this.targetSelection = holder.targetSelection;
+ this.targetSelectionSet = holder.targetSelectionSet;
+
+ map = holder.map;
}
public org.ajax4jsf.model.ExtendedDataModel createDataModel() {
+ Map source = null;
+
+ if (submittedValueHolder != null) {
+ source = submittedValueHolder.map;
+ } else {
+ source = this.map;
+ }
+
+ if (source != null) {
+ ListShuttleDataModel dataModel = new ListShuttleDataModel();
+ dataModel.setWrappedData(source);
+
+ return dataModel;
+ }
+
DataModel sourceDataModel = createDataModel(getSourceValue());
DataModel targetDataModel = createDataModel(getTargetValue());
- if (isTranslatedRenderingState() || isTranslatedState()) {
- Map sourceTranslationTable = null;
- Map targetTranslationTable = null;
-
- if (submittedValueHolder != null) {
- sourceTranslationTable = submittedValueHolder.sourceTranslationTable;
- targetTranslationTable = submittedValueHolder.targetTranslationTable;
- } else {
- sourceTranslationTable = this.sourceTranslationTable;
- targetTranslationTable = this.targetTranslationTable;
- }
-
- return new ListShuttleDataModel(sourceDataModel, targetDataModel,
- isTranslatedState(),
- sourceTranslationTable,
- targetTranslationTable);
- } else {
- return new ListShuttleDataModel(sourceDataModel, targetDataModel, false, null, null);
- }
+ ListShuttleDataModel dataModel = new ListShuttleDataModel();
+ dataModel.setWrappedData(new DataModel[]{sourceDataModel, targetDataModel});
+ return dataModel;
}
public void addValueChangeListener(ValueChangeListener listener) {
@@ -325,16 +341,36 @@
removeFacesListener(listener);
}
- public boolean isSource() {
- ListShuttleDataModel dataModel = (ListShuttleDataModel) getExtendedDataModel();
- return dataModel.isSource();
- }
+ protected final UpdateModelCommand updateTargetSelectionCommand = new UpdateModelCommand() {
- public boolean isTarget() {
- ListShuttleDataModel dataModel = (ListShuttleDataModel) getExtendedDataModel();
- return dataModel.isTarget();
- }
+ public void execute(FacesContext context) {
+ if (targetSelectionSet) {
+ ValueBinding vb = getValueBinding("targetSelection");
+ if (vb != null) {
+ vb.setValue(context, targetSelection);
+ targetSelection = null;
+ targetSelectionSet = false;
+ }
+ }
+ }
+
+ };
+
+ protected final UpdateModelCommand updateSourceSelectionCommand = new UpdateModelCommand() {
+ public void execute(FacesContext context) {
+ if (sourceSelectionSet) {
+ ValueBinding vb = getValueBinding("sourceSelection");
+ if (vb != null) {
+ vb.setValue(context, sourceSelection);
+ sourceSelection = null;
+ sourceSelectionSet = false;
+ }
+ }
+ }
+
+ };
+
private final UpdateModelCommand updateSourceCommand = new UpdateModelCommand() {
public void execute(FacesContext context) {
@@ -408,7 +444,8 @@
}
updateModel(context, updateActiveItemCommand);
- updateModel(context, updateSelectionCommand);
+ updateModel(context, updateSourceSelectionCommand);
+ updateModel(context, updateTargetSelectionCommand);
updateModel(context, updateSourceCommand);
updateModel(context, updateTargetCommand);
}
@@ -470,47 +507,32 @@
Object newTargetValue = oldTargetValue;
try {
+ final ArrayList sourceList = new ArrayList();
+ final ArrayList targetList = new ArrayList();
+
final ListShuttleDataModel listShuttleDataModel = (ListShuttleDataModel) getExtendedDataModel();
-
- listShuttleDataModel.setSourceTranslationTable(submittedValueHolder.getSourceTranslationTable());
- listShuttleDataModel.setTargetTranslationTable(submittedValueHolder.getTargetTranslationTable());
-
try {
- if (listShuttleDataModel.needSourceTranslation()) {
- final DataAdder sourceValueAdder = createDataAdder(oldSourceValue, listShuttleDataModel.getSourceRowCount());
- listShuttleDataModel.walkSource(context, new DataVisitor() {
+ listShuttleDataModel.walk(context, new DataVisitor() {
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
- setRowKey(rowKey);
- sourceValueAdder.add(getRowData());
+ setRowKey(context, rowKey);
+
+ ListShuttleRowKey listShuttleRowKey = (ListShuttleRowKey) rowKey;
+ if (listShuttleRowKey.isFacadeSource()) {
+ sourceList.add(getRowData());
+ } else {
+ targetList.add(getRowData());
}
-
- }, null, null);
-
- newSourceValue = sourceValueAdder.getContainer();
- }
-
- if (listShuttleDataModel.needTargetTranslation()) {
- final DataAdder targetValueAdder = createDataAdder(oldTargetValue, listShuttleDataModel.getTargetRowCount());
- listShuttleDataModel.walkTarget(context, new DataVisitor() {
-
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- setRowKey(rowKey);
- targetValueAdder.add(getRowData());
- }
-
- }, null, null);
-
- newTargetValue = targetValueAdder.getContainer();
- }
-
+ }
+ }, null, null);
} catch (IOException e) {
throw new ConverterException(e.getLocalizedMessage(), e);
}
+
+ newSourceValue = createContainer(sourceList, oldSourceValue.getClass());
+ newTargetValue = createContainer(targetList, oldTargetValue.getClass());
}
catch (ConverterException ce) {
Object submittedValue = submittedValueHolder;
@@ -523,13 +545,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(sets[0]);
- setActiveItem(sets[1]);
+ setSourceSelection(submittedValueHolder.sourceSelection);
+ setTargetSelection(submittedValueHolder.targetSelection);
+ setActiveItem(submittedValueHolder.activeItem);
Object previousSource = getSourceValue();
Object previousTarget = getTargetValue();
@@ -545,8 +563,7 @@
new Object[]{newSourceValue, newTargetValue}));
}
- this.sourceTranslationTable = this.submittedValueHolder.sourceTranslationTable;
- this.targetTranslationTable = this.submittedValueHolder.targetTranslationTable;
+ this.map = this.submittedValueHolder.map;
this.submittedValueHolder = null;
@@ -556,24 +573,19 @@
protected void resetDataModel() {
super.resetDataModel();
- this.sourceTranslationTable = null;
- this.targetTranslationTable = null;
+ this.map = null;
if (this.submittedValueHolder != null) {
setTranslatedRenderingState();
}
}
- public Object getTranslatedRowKey() {
- return ((ListShuttleDataModel) getExtendedDataModel()).getTranslatedRowKey();
- }
-
public ItemState getItemState() {
if (submittedValueHolder != null) {
- return new SubmittedItemState(submittedValueHolder.getSelection(),
- submittedValueHolder.getActiveItems());
+ return new ModelItemState(submittedValueHolder.sourceSelection, submittedValueHolder.targetSelection,
+ submittedValueHolder.activeItem);
} else {
- return new ModelItemState(getSelection(), getActiveItem());
+ return new ModelItemState(getSourceSelection(), getTargetSelection(), getActiveItem());
}
}
@@ -588,4 +600,41 @@
public abstract boolean isFastMoveControlsVisible();
public abstract void setFastMoveControlsVisible(boolean visible);
+
+ public Collection getSourceSelection() {
+ if (this.sourceSelection != null) {
+ return this.sourceSelection;
+ } else {
+ ValueBinding vb = getValueBinding("sourceSelection");
+ if (vb != null) {
+ return (Collection) vb.getValue(FacesContext.getCurrentInstance());
+ }
+ }
+
+ return null;
+ }
+
+ public void setSourceSelection(Collection collection) {
+ this.sourceSelection = collection;
+ this.sourceSelectionSet = true;
+ }
+
+ public Collection getTargetSelection() {
+ if (this.targetSelection != null) {
+ return this.targetSelection;
+ } else {
+ ValueBinding vb = getValueBinding("targetSelection");
+ if (vb != null) {
+ return (Collection) vb.getValue(FacesContext.getCurrentInstance());
+ }
+ }
+
+ return null;
+ }
+
+ public void setTargetSelection(Collection collection) {
+ this.targetSelection = collection;
+ this.targetSelectionSet = true;
+ }
+
}
Modified: branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleDataModel.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleDataModel.java 2007-12-04 05:21:18 UTC (rev 4432)
+++ branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleDataModel.java 2007-12-04 05:21:32 UTC (rev 4433)
@@ -4,7 +4,6 @@
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;
@@ -16,7 +15,6 @@
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
import org.ajax4jsf.model.SequenceDataModel;
-import org.ajax4jsf.model.SequenceRange;
/**
* @author Nick Belaevski
@@ -24,48 +22,15 @@
*/
public class ListShuttleDataModel extends ExtendedDataModel {
- private Object rowKey;
+ private ListShuttleRowKey rowKey;
- private Boolean useSourceFacade = null;
- private Boolean useSourceModel = null;
-
- private boolean translatedModel;
private SequenceDataModel sourceModel;
private SequenceDataModel targetModel;
- private Map sourceTranslationTable;
+ private Map data;
- private Map targetTranslationTable;
-
- protected static final class TranslatedRowKey implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = -7299475726153818934L;
-
- private Object rowKey;
-
- private String asString;
-
- public TranslatedRowKey(Object key, String asString) {
- super();
- this.rowKey = key;
- this.asString = asString;
- }
-
- public Object getRowKey() {
- return rowKey;
- }
-
- public String getAsString() {
- return asString;
- }
-
- public String toString() {
- return getAsString();
- }
- };
-
+ private Object wrappedData;
+
/* (non-Javadoc)
* @see org.ajax4jsf.model.ExtendedDataModel#getRowKey()
*/
@@ -73,259 +38,113 @@
return rowKey;
}
- private Object translate(Object key) {
- if (key != null) {
- if (sourceTranslationTable != null && sourceTranslationTable.containsKey(key)) {
- return sourceTranslationTable.get(key);
- } else if (targetTranslationTable != null && targetTranslationTable.containsKey(key)) {
- return targetTranslationTable.get(key);
- } else {
- return key;
- }
- } else {
- return key;
- }
- }
-
- private void setShuttleRowKey(ListShuttleRowKey shuttleRowKey) {
- Object sourceKey = null;
- Object targetKey = null;
- Boolean useSourceFacade = null;
- Boolean useSourceModel = null;
-
- if (shuttleRowKey != null) {
- if (shuttleRowKey.isSource()) {
- sourceKey = shuttleRowKey.getRowKey();
- useSourceModel = Boolean.TRUE;
- } else {
- targetKey = shuttleRowKey.getRowKey();
- useSourceModel = Boolean.FALSE;
- }
-
- useSourceFacade = (shuttleRowKey.isFacadeSource() ? Boolean.TRUE : Boolean.FALSE);
- }
-
- this.useSourceFacade = useSourceFacade;
- this.useSourceModel = useSourceModel;
-
- this.sourceModel.setRowKey(sourceKey);
- this.targetModel.setRowKey(targetKey);
- }
-
/* (non-Javadoc)
* @see org.ajax4jsf.model.ExtendedDataModel#setRowKey(java.lang.Object)
*/
public void setRowKey(Object key) {
- this.rowKey = key;
+ this.rowKey = (ListShuttleRowKey) key;
+ }
- if (key instanceof TranslatedRowKey) {
- ListShuttleRowKey shuttleRowKey = (ListShuttleRowKey) ((TranslatedRowKey) key).getRowKey();
- setShuttleRowKey(shuttleRowKey);
- } else {
- if (this.translatedModel) {
- if (rowKey != null) {
- setShuttleRowKey((ListShuttleRowKey) translate(key));
- } else {
- setShuttleRowKey(null);
- }
- } else {
- setShuttleRowKey((ListShuttleRowKey) key);
+ public void walk(final FacesContext context, final DataVisitor visitor, final Range range,
+ final Object argument) throws IOException {
+ if (data != null) {
+ Iterator iterator = data.entrySet().iterator();
+
+ while (iterator.hasNext()) {
+ Entry entry =(Map.Entry) iterator.next();
+
+ visitor.process(context, entry.getKey(), argument);
}
- }
- }
+
+ } else {
+ sourceModel.walk(context, new DataVisitor() {
- public ListShuttleDataModel(DataModel source, DataModel target,
- boolean translatedModel, Map sourceTranslationTable, Map targetTranslationTable) {
- super();
- this.translatedModel = translatedModel;
- this.sourceTranslationTable = sourceTranslationTable;
- this.targetTranslationTable = targetTranslationTable;
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
- this.sourceModel = new org.ajax4jsf.model.SequenceDataModel(source);
- this.targetModel = new org.ajax4jsf.model.SequenceDataModel(target);
- }
-
- private void walkModel(final FacesContext context, final DataVisitor visitor, Range range,
- Object argument, final boolean source) throws IOException {
-
- ExtendedDataModel dataModel = source ? this.sourceModel : this.targetModel;
-
- dataModel.walk(context, new DataVisitor() {
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- ListShuttleRowKey shuttleRowKey = new ListShuttleRowKey(rowKey, source);
- Object translatedShuttleRowKey = translate(shuttleRowKey);
-
- if (translatedModel) {
- visitor.process(context, new TranslatedRowKey(
- shuttleRowKey, String.valueOf(translatedShuttleRowKey)), argument);
- } else {
- visitor.process(context, translatedShuttleRowKey, argument);
+ ListShuttleRowKey key = new ListShuttleRowKey(rowKey, true);
+ visitor.process(context, key, argument);
}
- }
- }, new SequenceRange(0, -1), argument);
- }
+ }, range, argument);
- private void walkMap(final FacesContext context, final DataVisitor visitor, Range range,
- Object argument, Map translationMap) throws IOException {
+ targetModel.walk(context, new DataVisitor() {
- Iterator translations = translationMap.entrySet().iterator();
- while (translations.hasNext()) {
- Entry translation = (Entry) translations.next();
- ListShuttleRowKey sourceKey = (ListShuttleRowKey) translation.getKey();
- ListShuttleRowKey translatedKey = (ListShuttleRowKey) translation.getValue();
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
- if (translatedModel) {
- visitor.process(context, new TranslatedRowKey(
- translatedKey, String.valueOf(sourceKey)), argument);
- } else {
- visitor.process(context, sourceKey, argument);
- }
+ ListShuttleRowKey key = new ListShuttleRowKey(rowKey, false);
+ visitor.process(context, key, argument);
+ }
+
+ }, range, argument);
}
}
- public void walkSource(final FacesContext context, final DataVisitor visitor, Range range,
- Object argument) throws IOException {
-
- if (this.sourceTranslationTable != null) {
- this.walkMap(context, visitor, range, argument, this.sourceTranslationTable);
+ public int getRowCount() {
+ if (data != null) {
+ return data.size();
} else {
- this.walkModel(context, visitor, range, argument, true);
+ return sourceModel.getRowCount() + targetModel.getRowCount();
}
}
-
- public void walkTarget(final FacesContext context, final DataVisitor visitor, Range range,
- Object argument) throws IOException {
- if (this.targetTranslationTable != null) {
- this.walkMap(context, visitor, range, argument, this.targetTranslationTable);
- } else {
- this.walkModel(context, visitor, range, argument, false);
- }
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.model.ExtendedDataModel#walk(javax.faces.context.FacesContext, org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range, java.lang.Object)
- */
- public void walk(final FacesContext context, final DataVisitor visitor, Range range,
- Object argument) throws IOException {
-
- walkSource(context, visitor, range, argument);
- walkTarget(context, visitor, range, argument);
- }
-
- public Object getTranslatedRowKey() {
- return this.translate(getRowKey());
- }
-
- /* (non-Javadoc)
- * @see javax.faces.model.DataModel#getRowCount()
- */
- public int getRowCount() {
- return sourceModel.getRowCount() + targetModel.getRowCount();
- }
-
- /* (non-Javadoc)
- * @see javax.faces.model.DataModel#getRowData()
- */
public Object getRowData() {
- if (isSourceModel()) {
- return sourceModel.getRowData();
- } else if (isTargetModel()) {
- return targetModel.getRowData();
+ if (data != null) {
+ return data.get(rowKey);
} else {
- return null;
+ if (this.rowKey != null) {
+ if (this.rowKey.isSource()) {
+ return sourceModel.getRowData();
+ } else {
+ return targetModel.getRowData();
+ }
+ } else {
+ return null;
+ }
}
}
- /* (non-Javadoc)
- * @see javax.faces.model.DataModel#getRowIndex()
- */
public int getRowIndex() {
- return -1;
+ // TODO Auto-generated method stub
+ return 0;
}
- /* (non-Javadoc)
- * @see javax.faces.model.DataModel#getWrappedData()
- */
public Object getWrappedData() {
- // TODO Auto-generated method stub
- return null;
+ return wrappedData;
}
- /* (non-Javadoc)
- * @see javax.faces.model.DataModel#isRowAvailable()
- */
public boolean isRowAvailable() {
- if (isSourceModel()) {
- return sourceModel.isRowAvailable();
- } else if (isTargetModel()) {
- return targetModel.isRowAvailable();
+ if (data != null) {
+ return data.containsKey(rowKey);
} else {
- return false;
+ if (rowKey != null) {
+ if (rowKey.isSource()) {
+ return sourceModel.isRowAvailable();
+ } else {
+ return targetModel.isRowAvailable();
+ }
+ } else {
+ return false;
+ }
}
}
- /* (non-Javadoc)
- * @see javax.faces.model.DataModel#setRowIndex(int)
- */
public void setRowIndex(int rowIndex) {
- }
-
- /* (non-Javadoc)
- * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
- */
- public void setWrappedData(Object data) {
// TODO Auto-generated method stub
-
+
}
-
- public boolean needSourceTranslation() {
- return sourceTranslationTable != null;
- }
-
- public boolean needTargetTranslation() {
- return targetTranslationTable != null;
- }
- public int getSourceRowCount() {
- if (sourceTranslationTable != null) {
- return sourceTranslationTable.size();
+ public void setWrappedData(Object data) {
+ this.rowKey = null;
+ this.wrappedData = data;
+
+ if (data instanceof Map) {
+ this.data = (Map) data;
} else {
- return sourceModel.getRowCount();
+ DataModel[] models = (DataModel[]) data;
+ this.sourceModel = new SequenceDataModel(models[0]);
+ this.targetModel = new SequenceDataModel(models[1]);
}
}
- public int getTargetRowCount() {
- if (targetTranslationTable != null) {
- return targetTranslationTable.size();
- } else {
- return targetModel.getRowCount();
- }
- }
-
- protected boolean isSourceModel() {
- return Boolean.TRUE.equals(useSourceModel);
- }
-
- protected boolean isTargetModel() {
- return Boolean.FALSE.equals(useSourceModel);
- }
-
- public boolean isSource() {
- return Boolean.TRUE.equals(useSourceFacade);
- }
-
- public boolean isTarget() {
- return Boolean.FALSE.equals(useSourceFacade);
- }
-
- public void setSourceTranslationTable(Map sourceTranslationTable) {
- this.sourceTranslationTable = sourceTranslationTable;
- }
-
- public void setTargetTranslationTable(Map targetTranslationTable) {
- this.targetTranslationTable = targetTranslationTable;
- }
}
Modified: branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleRowKey.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleRowKey.java 2007-12-04 05:21:18 UTC (rev 4432)
+++ branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleRowKey.java 2007-12-04 05:21:32 UTC (rev 4433)
@@ -61,7 +61,7 @@
}
public String toString() {
- return (source ? "s" : "t") + rowKey.toString();
+ return (source ? "" : "t") + rowKey.toString();
}
public ListShuttleRowKey(Object rowKey, boolean source) {
Modified: branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java 2007-12-04 05:21:18 UTC (rev 4432)
+++ branches/3.1.x/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java 2007-12-04 05:21:32 UTC (rev 4433)
@@ -5,11 +5,17 @@
import java.io.IOException;
import java.io.StringWriter;
+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;
@@ -20,6 +26,7 @@
import org.richfaces.component.UIListShuttle;
import org.richfaces.component.UIOrderingBaseComponent;
import org.richfaces.component.UIOrderingBaseComponent.ItemState;
+import org.richfaces.model.ListShuttleRowKey;
/**
* @author Nick Belaevski
@@ -90,54 +97,86 @@
UIListShuttle table = (UIListShuttle) holder.getTable();
ListShuttleRendererTableHolder shuttleRendererTableHolder = (ListShuttleRendererTableHolder) holder;
- if (shuttleRendererTableHolder.isSource() && table.isSource() ||
- !shuttleRendererTableHolder.isSource() && table.isTarget()) {
-
- ResponseWriter writer = context.getResponseWriter();
- String clientId = holder.getTable().getClientId(context);
- writer.startElement(HTML.TR_ELEMENT, table);
- writer.writeAttribute("id", clientId, null);
+ ListShuttleRowKey listShuttleRowKey = (ListShuttleRowKey) table.getRowKey();
+ if (listShuttleRowKey != null) {
+ if (shuttleRendererTableHolder.isSource() == listShuttleRowKey.isFacadeSource()) {
+
+ ResponseWriter writer = context.getResponseWriter();
+ String clientId = holder.getTable().getClientId(context);
+ writer.startElement(HTML.TR_ELEMENT, table);
+ writer.writeAttribute("id", clientId, null);
- StringBuffer rowClassName = new StringBuffer("ol_normal rich-ordering-list-row");
- StringBuffer cellClassName = new StringBuffer("ol_cell rich-ordering-list-cell");
+ StringBuffer rowClassName = new StringBuffer("ol_normal rich-ordering-list-row");
+ StringBuffer cellClassName = new StringBuffer("ol_cell rich-ordering-list-cell");
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this, table);
- SelectionState selectionState = (SelectionState) variables.getVariable(SELECTION_STATE_VAR_NAME);
- ItemState itemState = getItemState(context, table, variables);
-
- boolean active = itemState.isActive();
- if (active) {
- rowClassName.append(" rich-ordering-list-row-active");
- cellClassName.append(" rich-ordering-list-cell-active");
- }
-
- boolean selected = itemState.isSelected();
- selectionState.addState(selected);
- if (selected) {
- rowClassName.append(" rich-ordering-list-row-selected");
- cellClassName.append(" rich-ordering-list-cell-selected");
- }
-
- writer.writeAttribute("class", rowClassName.toString(), null);
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(this, table);
+ SelectionState selectionState = (SelectionState) variables.getVariable(SELECTION_STATE_VAR_NAME);
+ ItemState itemState = getItemState(context, table, variables);
+
+ boolean active = itemState.isActive();
+ if (active) {
+ rowClassName.append(" rich-ordering-list-row-active");
+ cellClassName.append(" rich-ordering-list-cell-active");
+ }
+
+ boolean selected = itemState.isSelected();
+ selectionState.addState(selected);
+ if (selected) {
+ rowClassName.append(" rich-ordering-list-row-selected");
+ cellClassName.append(" rich-ordering-list-cell-selected");
+ }
+
+ writer.writeAttribute("class", rowClassName.toString(), null);
- List children = table.getChildren();
- for (Iterator iterator = children.iterator(); iterator.hasNext();) {
- UIComponent component = (UIComponent) iterator.next();
+ boolean columnRendered = false;
- if (component instanceof UIColumn && component.isRendered()) {
- UIColumn column = (UIColumn) component;
+ List children = table.getChildren();
+ for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+ UIComponent component = (UIComponent) iterator.next();
- writer.startElement(HTML.td_ELEM, table);
+ if (component instanceof UIColumn && component.isRendered()) {
+ UIColumn column = (UIColumn) component;
- writer.writeAttribute("class", cellClassName.toString(), null);
+ writer.startElement(HTML.td_ELEM, table);
- renderChildren(context, column);
+ writer.writeAttribute("class", cellClassName.toString(), null);
- writer.endElement(HTML.td_ELEM);
+ renderChildren(context, column);
+
+ if (!columnRendered) {
+ writer.startElement(HTML.INPUT_ELEM, table);
+ 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.writeAttribute(HTML.id_ATTRIBUTE, clientId + "StateInput", null);
+
+ writer.endElement(HTML.INPUT_ELEM);
+
+ columnRendered = true;
+ }
+
+ writer.endElement(HTML.td_ELEM);
+ }
}
+
+ writer.endElement(HTML.TR_ELEMENT);
}
-
- writer.endElement(HTML.TR_ELEMENT);
}
}
@@ -207,18 +246,64 @@
return s == null || s.length() == 0;
}
- protected void doDecode(FacesContext context, UIComponent component) {
- super.doDecode(context, component);
+ public void doDecode(FacesContext context, UIComponent component) {
+ UIListShuttle listShuttle = (UIListShuttle) component;
+
+ String clientId = listShuttle.getBaseClientId(context);
+ ExternalContext externalContext = context.getExternalContext();
+ Map requestParameterMap = externalContext
+ .getRequestParameterMap();
+
+ if (requestParameterMap.containsKey(clientId)) {
+ Set sourceSelection = new HashSet();
+ Set targetSelection = new HashSet();
+ Object activeItem = null;
+ String[] strings = (String[]) externalContext.getRequestParameterValuesMap().get(clientId);
+ Map map = new LinkedHashMap();
+
+ boolean facadeSource = true;
+
+ for (int i = 0; i < strings.length; i++) {
+ String string = strings[i];
+
+ if (":".equals(string)) {
+ facadeSource = false;
+ continue;
+ }
+
+ int idx = string.indexOf(':');
+ Object value = getAsObject(context, listShuttle, string.substring(idx + 1));
+ String substring = string.substring(0, idx);
+
+ boolean target = false;
+ if (substring.charAt(0) == 't') {
+ target = true;
+ }
- String clientId = component.getClientId(context);
- Object object = context.getExternalContext().getRequestParameterValuesMap().get(clientId);
- if (object != null) {
- String[] submittedValues = (String[]) object;
- if (submittedValues.length == 2 && (!isEmpty(submittedValues[0]) || !isEmpty(submittedValues[1]))) {
- UIListShuttle listShuttle = (UIListShuttle) component;
- listShuttle.setSubmittedStrings(submittedValues);
- }
- }
+ boolean selected = false;
+
+ idx = substring.length() - 1;
+
+ if (substring.charAt(idx) == 'a') {
+ activeItem = value;
+ idx--;
+ }
+
+ if (substring.charAt(idx) == 's') {
+ (target ? targetSelection : sourceSelection).add(value);
+ idx--;
+ }
+
+
+ substring = substring.substring(target ? 1 : 0, idx + 1);
+
+ Object key = new ListShuttleRowKey(new Integer(substring), target, facadeSource);
+ map.put(key, value);
+ }
+ listShuttle.setSubmittedStrings(map, sourceSelection, targetSelection, activeItem);
+ } else {
+ listShuttle.setSubmittedStrings(new HashMap(0), null, null, null);
+ }
}
}
Modified: branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx 2007-12-04 05:21:18 UTC (rev 4432)
+++ branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx 2007-12-04 05:21:32 UTC (rev 4433)
@@ -48,8 +48,6 @@
<table id="#{clientId}" class="rich-list-shuttle">
<tr>
<td>
- <input id="#{clientId}valueKeeper" type="hidden" name="#{clientId}" value="#{component.sourceSubmittedString}"/>
- <input id="#{clientId}tlValueKeeper" type="hidden" name="#{clientId}" value="#{component.targetSubmittedString}"/>
<div>
<input id="#{clientId}focusKeeper" type="button" value="" style="width: 1px; position: absolute; left: -32767px;" name="focusKeeper"/>
@@ -114,6 +112,8 @@
</td>
<td>
<div>
+ <input type="hidden" value=":" style="display: none;" name="#{clientId}" />
+
<input id="#{clientId}tlFocusKeeper" type="button" value="" style="width: 1px; position: absolute; left: -32767px;" name="focusKeeper"/>
<table id="#{clientId}tlTable" cellpadding="0" cellspacing="0" class="ol_body">
@@ -182,8 +182,8 @@
Event.onReady(function() {
var cotrolsIdPrefix = [['up', 'disup'], ['down', 'disdown'], ['last', 'dislast'], ['first','disfirst']];
var listShuttleCotrolsIdPrefix = [['copy', 'discopy'], ['copyAll', 'discopyAll'], ['remove', 'disremove'], ['removeAll','disremoveAll']];
- var listShuttle = new Richfaces.ListShuttle(new Richfaces.OrderingList('#{cId}', '#{cId}tlInternal_tab', '#{cId}tlInternal_header_tab', '#{cId}tlFocusKeeper', '#{cId}tlValueKeeper', cotrolsIdPrefix, '#{cId}sortLabel', function() {#{component.attributes['onorderchanged']}}),
- new Richfaces.ListBase('#{cId}', '#{cId}internal_tab', '#{cId}internal_header_tab', '#{cId}focusKeeper', '#{cId}valueKeeper'),
+ var listShuttle = new Richfaces.ListShuttle(new Richfaces.OrderingList('#{cId}', '#{cId}tlInternal_tab', '#{cId}tlInternal_header_tab', '#{cId}tlFocusKeeper', cotrolsIdPrefix, '#{cId}sortLabel', function() {#{component.attributes['onorderchanged']}}),
+ new Richfaces.ListBase('#{cId}', '#{cId}internal_tab', '#{cId}internal_header_tab', '#{cId}focusKeeper'),
"#{cId}", listShuttleCotrolsIdPrefix, "#{switchByClick}");
var sourceLayoutManager = new LayoutManager('#{cId}internal_header_tab', '#{cId}internal_tab');
var targetLayoutManager = new LayoutManager('#{cId}tlInternal_header_tab', '#{cId}tlInternal_tab');
16 years, 5 months
JBoss Rich Faces SVN: r4432 - in branches/3.1.x/samples/listShuttleDemo/src/main: webapp/WEB-INF and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-12-04 00:21:18 -0500 (Tue, 04 Dec 2007)
New Revision: 4432
Added:
branches/3.1.x/samples/listShuttleDemo/src/main/java/org/richfaces/ListShuttleOptionItemConverter.java
Modified:
branches/3.1.x/samples/listShuttleDemo/src/main/java/org/richfaces/ListShuttleOptionItem.java
branches/3.1.x/samples/listShuttleDemo/src/main/webapp/WEB-INF/faces-config.xml
branches/3.1.x/samples/listShuttleDemo/src/main/webapp/pages/index.jsp
Log:
latest changes for listShuttle & orderingList
Modified: branches/3.1.x/samples/listShuttleDemo/src/main/java/org/richfaces/ListShuttleOptionItem.java
===================================================================
--- branches/3.1.x/samples/listShuttleDemo/src/main/java/org/richfaces/ListShuttleOptionItem.java 2007-12-03 20:37:53 UTC (rev 4431)
+++ branches/3.1.x/samples/listShuttleDemo/src/main/java/org/richfaces/ListShuttleOptionItem.java 2007-12-04 05:21:18 UTC (rev 4432)
@@ -39,4 +39,30 @@
public void action() {
System.out.println("ListShuttleOptionItem.action() " + this.toString());
}
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + price;
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ListShuttleOptionItem other = (ListShuttleOptionItem) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (price != other.price)
+ return false;
+ return true;
+ }
}
Added: branches/3.1.x/samples/listShuttleDemo/src/main/java/org/richfaces/ListShuttleOptionItemConverter.java
===================================================================
--- branches/3.1.x/samples/listShuttleDemo/src/main/java/org/richfaces/ListShuttleOptionItemConverter.java (rev 0)
+++ branches/3.1.x/samples/listShuttleDemo/src/main/java/org/richfaces/ListShuttleOptionItemConverter.java 2007-12-04 05:21:18 UTC (rev 4432)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.richfaces;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+/**
+ * @author mikalaj
+ *
+ */
+public class ListShuttleOptionItemConverter implements Converter {
+
+ /* (non-Javadoc)
+ * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
+ */
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value) {
+
+ int index = value.indexOf(':');
+
+ return new ListShuttleOptionItem(value.substring(0, index), Integer.valueOf(value.substring(index + 1)));
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
+ */
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value) {
+
+ ListShuttleOptionItem optionItem = (ListShuttleOptionItem) value;
+ return optionItem.getName() + ":" + optionItem.getPrice();
+ }
+
+}
Modified: branches/3.1.x/samples/listShuttleDemo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- branches/3.1.x/samples/listShuttleDemo/src/main/webapp/WEB-INF/faces-config.xml 2007-12-03 20:37:53 UTC (rev 4431)
+++ branches/3.1.x/samples/listShuttleDemo/src/main/webapp/WEB-INF/faces-config.xml 2007-12-04 05:21:18 UTC (rev 4432)
@@ -19,4 +19,10 @@
<managed-bean-class>org.richfaces.SkinBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+
+ <managed-bean>
+ <managed-bean-name>converter</managed-bean-name>
+ <managed-bean-class>org.richfaces.ListShuttleOptionItemConverter</managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
+ </managed-bean>
</faces-config>
Modified: branches/3.1.x/samples/listShuttleDemo/src/main/webapp/pages/index.jsp
===================================================================
--- branches/3.1.x/samples/listShuttleDemo/src/main/webapp/pages/index.jsp 2007-12-03 20:37:53 UTC (rev 4431)
+++ branches/3.1.x/samples/listShuttleDemo/src/main/webapp/pages/index.jsp 2007-12-04 05:21:18 UTC (rev 4432)
@@ -25,6 +25,7 @@
fastOrderControlsVisible="#{listShuttleDemoBean.fastOrderControlsVisible}"
moveControlsVisible="#{listShuttleDemoBean.moveControlsVisible}"
fastMoveControlsVisible="#{listShuttleDemoBean.fastMoveControlsVisible}"
+ converter="#{converter}"
>
<h:column><h:outputText value="#{item.name}" /></h:column>
<h:column><h:outputText value="#{item.price}" /></h:column>
16 years, 5 months
JBoss Rich Faces SVN: r4431 - in branches/3.1.x: ui/listShuttle/src/test/java/org/richfaces/component and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: sergeyhalipov
Date: 2007-12-03 15:37:53 -0500 (Mon, 03 Dec 2007)
New Revision: 4431
Added:
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/MockExternalContext.java
Modified:
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java
branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/ListShuttleRenderingTest.java
Log:
List shuttle JUnit tests (not finished).
http://jira.jboss.com/jira/browse/RF-1178
Modified: branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
--- branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-12-03 17:09:06 UTC (rev 4430)
+++ branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-12-03 20:37:53 UTC (rev 4431)
@@ -179,6 +179,9 @@
while (resources.hasMoreElements()) {
parser.parse((URL) resources.nextElement());
}
+
+ externalContext = new MockExternalContext(externalContext);
+ facesContext.setExternalContext(externalContext);
}
protected WebClient createWebClient() {
Added: branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/MockExternalContext.java
===================================================================
--- branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/MockExternalContext.java (rev 0)
+++ branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/MockExternalContext.java 2007-12-03 20:37:53 UTC (rev 4431)
@@ -0,0 +1,58 @@
+/**
+ * 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.ajax4jsf.tests;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.shale.test.mock.MockExternalContext12;
+
+/**
+ * @author Siarhej Chalipau
+ *
+ */
+public class MockExternalContext extends MockExternalContext12 {
+
+ public MockExternalContext(org.apache.shale.test.mock.MockExternalContext baseContext) {
+ super((ServletContext)baseContext.getContext(),
+ (HttpServletRequest)baseContext.getRequest(), (HttpServletResponse)baseContext.getResponse());
+ }
+
+ public Map getRequestParameterValuesMap() {
+ // Method is unimplemented in org.apache.shale.test.mock.MockExternalContext and
+ // throws there UnsupportedOperationException
+ Map map = new HashMap();
+ HttpServletRequest request = (HttpServletRequest)getRequest();
+ for ( Enumeration e = request.getParameterNames(); e.hasMoreElements(); ) {
+ String name = (String) e.nextElement();
+ map.put(name, request.getParameterValues(name));
+ }
+ return Collections.unmodifiableMap(map);
+ }
+
+}
Modified: branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java 2007-12-03 17:09:06 UTC (rev 4430)
+++ branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java 2007-12-03 20:37:53 UTC (rev 4431)
@@ -21,36 +21,168 @@
package org.richfaces.component;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.component.UICommand;
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlCommandLink;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
/**
* Unit test for simple Component.
*/
public class ListShuttleComponentTest extends AbstractAjax4JsfTestCase {
+ private UIForm form = null;
+ private UIListShuttle listShuttle = null;
+ private ListShuttleBean sourceBean = null;
+ private ListShuttleBean targetBean = null;
+ private UICommand command = null;
+
/**
* Create the test case
*
* @param testName name of the test case
*/
- public ListShuttleComponentTest( String testName )
- {
+ public ListShuttleComponentTest( String testName ) {
super( testName );
}
public void setUp() throws Exception {
super.setUp();
+
+ application.addComponent(UIListShuttle.COMPONENT_TYPE, "org.richfaces.component.html.HtmlListShuttle");
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ command = new HtmlCommandLink();
+ command.setId("command");
+ command.setValue("test command");
+ form.getChildren().add(command);
+
+ sourceBean = new ListShuttleBean(false);
+ targetBean = new ListShuttleBean();
+
+ listShuttle = (UIListShuttle)application.createComponent(UIListShuttle.COMPONENT_TYPE);
+ listShuttle.setId("listShuttle");
+ listShuttle.setVar("item");
+ listShuttle.setValueBinding("sourceValue", new ValueBinding() {
+
+ public Class getType(FacesContext arg0) throws EvaluationException,
+ PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext arg0)
+ throws EvaluationException, PropertyNotFoundException {
+ return sourceBean.getValue();
+ }
+
+ public boolean isReadOnly(FacesContext arg0)
+ throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext arg0, Object arg1)
+ throws EvaluationException, PropertyNotFoundException {
+ assertTrue(arg1 instanceof List);
+ sourceBean.setValue((List)arg1);
+ }
+
+ });
+
+ listShuttle.setValueBinding("targetValue", new ValueBinding() {
+
+ public Class getType(FacesContext arg0) throws EvaluationException,
+ PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext arg0)
+ throws EvaluationException, PropertyNotFoundException {
+ return targetBean.getValue();
+ }
+
+ public boolean isReadOnly(FacesContext arg0)
+ throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext arg0, Object arg1)
+ throws EvaluationException, PropertyNotFoundException {
+ assertTrue(arg1 instanceof List);
+ targetBean.setValue((List)arg1);
+ }
+
+ });
+
+ form.getChildren().add(listShuttle);
}
public void tearDown() throws Exception {
+ form = null;
+ listShuttle = null;
+ sourceBean = null;
+ targetBean = null;
+ command = null;
+
super.tearDown();
}
/**
- * Rigourous Test :-)
+ * Tests if component accepts request parameters and stores them in submittedValue().
+ * If component is immediate, validation (possibly with conversion) should occur on that phase.
+ *
+ * @throws Exception
*/
- public void testComponent()
- {
- assertTrue( true );
+ public void testDecode() throws Exception {
+ HtmlPage view = renderView();
+ assertNotNull(view);
+
+ HtmlAnchor anchor = (HtmlAnchor)view.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
+ anchor.click();
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "1sa,0");
+ listShuttle.processDecodes(facesContext);
+ Object submittedValue = listShuttle.getSubmittedValue();
+ assertNotNull(submittedValue);
+
+ assertTrue(submittedValue instanceof Object[]);
+ assertEquals(2, ((Object[])submittedValue).length);
}
+
+ protected class ListShuttleBean {
+ private List value = null;
+
+ public ListShuttleBean() {
+ this(true);
+ }
+
+ public ListShuttleBean(boolean empty) {
+ value = new ArrayList();
+ if (!empty) {
+ value.add("1");
+ value.add("2");
+ }
+ }
+
+ public List getValue() {
+ return value;
+ }
+
+ public void setValue(List value) {
+ this.value = value;
+ }
+ }
}
Modified: branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/ListShuttleRenderingTest.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/ListShuttleRenderingTest.java 2007-12-03 17:09:06 UTC (rev 4430)
+++ branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/ListShuttleRenderingTest.java 2007-12-03 20:37:53 UTC (rev 4431)
@@ -193,7 +193,7 @@
inputs = view.getDocumentElement().getHtmlElementsByAttribute("input", "name", listShuttle.getClientId(facesContext));
assertNotNull(inputs);
- assertEquals(1, inputs.size());
+ assertEquals(2, inputs.size());
}
/**
16 years, 5 months
JBoss Rich Faces SVN: r4430 - in branches/3.1.x/ui/listShuttle/src/main: resources/org/richfaces/renderkit/html/scripts and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: vmolotkov
Date: 2007-12-03 12:09:06 -0500 (Mon, 03 Dec 2007)
New Revision: 4430
Modified:
branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml
branches/3.1.x/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/scripts/ListShuttle.js
branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx
Log:
attribute switchByClick was added
Modified: branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml 2007-12-03 17:05:24 UTC (rev 4429)
+++ branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml 2007-12-03 17:09:06 UTC (rev 4430)
@@ -65,6 +65,11 @@
<description>Collection which stores a set of selected items</description>
</property>
+ <property>
+ <name>switchByClick</name>
+ <classname>boolean</classname>
+ <defaultvalue>false</defaultvalue>
+ </property>
<property>
<name>sourceListWidth</name>
<classname>java.lang.String</classname>
Modified: branches/3.1.x/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/scripts/ListShuttle.js
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/scripts/ListShuttle.js 2007-12-03 17:05:24 UTC (rev 4429)
+++ branches/3.1.x/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/scripts/ListShuttle.js 2007-12-03 17:09:06 UTC (rev 4430)
@@ -3,7 +3,7 @@
Richfaces.ListShuttle = Class.create();
Richfaces.ListShuttle.prototype = {
- initialize: function(targetList, sourceList, clientId, controlIds) {
+ initialize: function(targetList, sourceList, clientId, controlIds, switchByClick) {
sourceList._onclickHandler = sourceList.onclickHandler;
sourceList.onclickHandler = function(e) { this.onclickHandler(e, sourceList); }.bindAsEventListener(this);
targetList._onclickHandler = targetList.onclickHandler;
@@ -15,6 +15,11 @@
this.targetList.shuttleTable.observe("dblclick", function(e) {this.moveItemByClick(window.event||e, this.targetList, this.sourceList)}.bindAsEventListener(this));
this.sourceList.shuttleTable.observe("dblclick", function(e) {this.moveItemByClick(window.event||e, this.sourceList, this.targetList)}.bindAsEventListener(this));
+ if (switchByClick == "true") {
+ this.targetList.shuttleTable.observe("click", function(e) {this.moveItemByClick(window.event||e, this.targetList, this.sourceList)}.bindAsEventListener(this));
+ this.sourceList.shuttleTable.observe("click", function(e) {this.moveItemByClick(window.event||e, this.sourceList, this.targetList)}.bindAsEventListener(this));
+ }
+
this.controlList = new Array();
this.initControlList(clientId, controlIds);
},
Modified: branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx 2007-12-03 17:05:24 UTC (rev 4429)
+++ branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx 2007-12-03 17:09:06 UTC (rev 4430)
@@ -41,8 +41,8 @@
variables.setVariable(SELECTION_STATE_VAR_NAME, targetSelectionState);
String encodedTargetRows = encodeRows(context, component, false);
- //boolean switchByClick = (boolean) component.getAttributes().get("switchByClick");
- //variables.setVariable("switchByClick", switchByClick);
+ Boolean switchByClick = (Boolean) component.getAttributes().get("switchByClick");
+ variables.setVariable("switchByClick", switchByClick);
]]>
</jsp:scriptlet>
<table id="#{clientId}" class="rich-list-shuttle">
@@ -184,7 +184,7 @@
var listShuttleCotrolsIdPrefix = [['copy', 'discopy'], ['copyAll', 'discopyAll'], ['remove', 'disremove'], ['removeAll','disremoveAll']];
var listShuttle = new Richfaces.ListShuttle(new Richfaces.OrderingList('#{cId}', '#{cId}tlInternal_tab', '#{cId}tlInternal_header_tab', '#{cId}tlFocusKeeper', '#{cId}tlValueKeeper', cotrolsIdPrefix, '#{cId}sortLabel', function() {#{component.attributes['onorderchanged']}}),
new Richfaces.ListBase('#{cId}', '#{cId}internal_tab', '#{cId}internal_header_tab', '#{cId}focusKeeper', '#{cId}valueKeeper'),
- "#{cId}", listShuttleCotrolsIdPrefix);
+ "#{cId}", listShuttleCotrolsIdPrefix, "#{switchByClick}");
var sourceLayoutManager = new LayoutManager('#{cId}internal_header_tab', '#{cId}internal_tab');
var targetLayoutManager = new LayoutManager('#{cId}tlInternal_header_tab', '#{cId}tlInternal_tab');
sourceLayoutManager.widthSynchronization();
16 years, 5 months
JBoss Rich Faces SVN: r4429 - in trunk: ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2007-12-03 12:05:24 -0500 (Mon, 03 Dec 2007)
New Revision: 4429
Modified:
trunk/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
Log:
RF-1391, RF-1478
todayControlMode parameter added - today control button action: "scroll", "select", "hidden"
Modified: trunk/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp
===================================================================
--- trunk/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp 2007-12-03 16:38:07 UTC (rev 4428)
+++ trunk/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp 2007-12-03 17:05:24 UTC (rev 4429)
@@ -38,7 +38,7 @@
</h:panelGrid>
<br />
<br />
- <calendar:calendar datePattern="#{calendarBean.pattern}" showApplyButton="#{calendarBean.showApplyButton}" popup="#{calendarBean.popup}"/>
+ <calendar:calendar todayControlMode="#{calendarBean.todayControlMode}" datePattern="#{calendarBean.pattern}" showApplyButton="#{calendarBean.showApplyButton}" popup="#{calendarBean.popup}"/>
<calendar:calendar cellWidth="5" cellHeight="5"/>
<calendar:calendar cellWidth="40" cellHeight="40"/>
<calendar:calendar
Modified: trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
--- trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-12-03 16:38:07 UTC (rev 4428)
+++ trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-12-03 17:05:24 UTC (rev 4429)
@@ -464,6 +464,11 @@
// "inactive" or undefined - no action (default)
// "scroll" - change current month
// "select" - change current month and select date
+ //
+ // todayControlMode - today control onclick action:
+ // "scroll"
+ // "select"
+ // "hidden"
// isDayEnabled - end-developer JS function
// dayStyleClass - end-developer JS function that provide style class for day's cells.
@@ -509,6 +514,7 @@
this.selectedDate = this.params.selectedDate;
if (typeof this.params.boundaryDatesMode=="string") this.params.boundaryDatesMode = this.params.boundaryDatesMode.toLowerCase();
+ if (typeof this.params.todayControlMode=="string") this.todayControlMode = this.params.todayControlMode.toLowerCase();
//
if (typeof this.params.isDayEnabled != "function") this.params.isDayEnabled = function (context) {return true;};
@@ -1140,6 +1146,12 @@
}
this.render();
+
+ if (typeof this.afterLoad=='function')
+ {
+ this.afterLoad();
+ this.afterLoad=null;
+ }
},
indexData:function(daysData, isAjaxMode) {
@@ -1330,7 +1342,6 @@
while (element)
{
- // TODO rich-calendar-spec class not implemented
// TODO fix start/stop event's calls
this.stopCellEvents(element);
@@ -1493,12 +1504,14 @@
},
today: function(noUpdate, noHighlight) {
+
var now = new Date();
+
var nowyear = now.getFullYear();
var nowmonth = now.getMonth();
var nowdate = now.getDate();
var updateflag = false;
-
+
if (nowdate!=this.todayDate.getDate()) {updateflag=true; this.todayDate = now;}
if (nowyear != this.currentDate.getFullYear() || nowmonth != this.currentDate.getMonth() )
@@ -1506,9 +1519,14 @@
updateflag = true;
this.currentDate = new Date(nowyear, nowmonth, 1);
}
+
+ if (this.todayControlMode=='select')
+ {
+ noHighlight=true;
+ }
if (updateflag)
- {
+ {
if (noUpdate) this.render(); else this.onUpdate();
}
else
@@ -1525,7 +1543,28 @@
}
}
}
+
+ // todayControl select mode
+ if (this.todayControlMode=='select')
+ if (updateflag && !noUpdate && this.submitFunction)
+ {
+ this.afterLoad = this.selectToday;
+ }
+ else this.selectToday();
+
},
+
+ selectToday: function()
+ {
+ if (this.todayCellId)
+ {
+ var daydata = this.days[parseInt($(this.todayCellId).id.substr(this.DATE_ELEMENT_ID.length),10)];
+ if (daydata.enabled && this.selectDate(new Date(),true) && !this.showApplyButton)
+ {
+ this.doCollapse();
+ }
+ }
+ },
onHighlightFinish: function (object)
{
@@ -1533,6 +1572,7 @@
},
selectDate: function(date, noUpdate, eventData) {
+
if (!eventData)
{
eventData = {event: null, element: null};
@@ -1554,7 +1594,7 @@
{
newSelectedDate = null;
}
-
+
// fire user event
var flag = true;
var isDateChanged = false;
@@ -1562,15 +1602,15 @@
{
isDateChanged = true
flag = this.invokeEvent("dateselect", eventData.element, eventData.event, date)
- }
-
+ }
+
if (flag)
{
var field = $(this.INPUT_DATE_ID);
this.selectedDate = newSelectedDate;
if (this.selectedDate!=null)
{
- if (!isDateParsed)
+ if (this.timeType && !isDateParsed)
if (oldSelectedDate!=null)
{
this.selectedDate.setHours(oldSelectedDate.getHours());
@@ -1626,7 +1666,11 @@
{
this.renderHF();
}
+
+ var todayControlMode = this.todayControlMode;
+ this.todayControlMode = '';
this.today(noUpdate, true);
+ this.todayControlMode = todayControlMode;
}
// call user event
@@ -1788,7 +1832,7 @@
CalendarView.nextMonthControl = CalendarView.getControl(">", CalendarView.toolButtonAttributes, "nextMonth");
CalendarView.previousMonthControl = CalendarView.getControl("<", CalendarView.toolButtonAttributes, "prevMonth");
CalendarView.currentMonthControl = function (context) { return Richfaces.Calendar.formatDate(context.calendar.getCurrentDate(), "MMMM, yyyy", context.monthLabels, context.monthLabelsShort);};
-CalendarView.todayControl = CalendarView.getControl("Today", CalendarView.toolButtonAttributes, "today");
+CalendarView.todayControl = function (context) { return (context.calendar.todayControlMode!='hidden' ? CalendarView.getControl("Today", CalendarView.toolButtonAttributes, "today") : "");};
CalendarView.selectedDateControl = function (context) { return CalendarView.getSelectedDateControl(context.calendar);};
CalendarView.timeControl = function (context) { return CalendarView.getTimeControl(context.calendar);};
CalendarView.closeControl = CalendarView.getControl("x", CalendarView.toolButtonAttributes, "close", "false");
16 years, 5 months
JBoss Rich Faces SVN: r4428 - trunk/docs/userguide/en/src/main/docbook/included.
by richfaces-svn-commits@lists.jboss.org
Author: vkorluzhenko
Date: 2007-12-03 11:38:07 -0500 (Mon, 03 Dec 2007)
New Revision: 4428
Modified:
trunk/docs/userguide/en/src/main/docbook/included/dataTable.xml
Log:
http://jira.jboss.com/jira/browse/RF-657 - fixed errors in the example
Modified: trunk/docs/userguide/en/src/main/docbook/included/dataTable.xml
===================================================================
--- trunk/docs/userguide/en/src/main/docbook/included/dataTable.xml 2007-12-03 16:36:22 UTC (rev 4427)
+++ trunk/docs/userguide/en/src/main/docbook/included/dataTable.xml 2007-12-03 16:38:07 UTC (rev 4428)
@@ -120,8 +120,8 @@
</para>
<programlisting role="XML"><![CDATA[...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5">
- <f:facet name="caption">United States Capitals</f:facet>
- <f:facet name="header">Capitals and States Table</f:facet>
+ <f:facet name="caption"><h:outputText value="United States Capitals" /></f:facet>
+ <f:facet name="header"><h:outputText value="Capitals and States Table" /></f:facet>
<rich:column>
<f:facet name="header">State Flag</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
@@ -142,7 +142,7 @@
<h:outputText value="#{cap.timeZone}"/>
<f:facet name="footer">Time Zone</f:facet>
</rich:column>
- <f:facet name="footer">Capitals and States Table</f:facet>
+ <f:facet name="footer"><h:outputText value="Capitals and States Table" /></f:facet>
</rich:dataTable>
...
]]></programlisting>
16 years, 5 months
JBoss Rich Faces SVN: r4427 - trunk/docs/userguide/en/src/main/docbook/included.
by richfaces-svn-commits@lists.jboss.org
Author: vkorluzhenko
Date: 2007-12-03 11:36:22 -0500 (Mon, 03 Dec 2007)
New Revision: 4427
Modified:
trunk/docs/userguide/en/src/main/docbook/included/orderingList.desc.xml
trunk/docs/userguide/en/src/main/docbook/included/orderingList.xml
Log:
http://jira.jboss.com/jira/browse/RF-1184 - checked section "Details of usage", fixed some errors
Modified: trunk/docs/userguide/en/src/main/docbook/included/orderingList.desc.xml
===================================================================
--- trunk/docs/userguide/en/src/main/docbook/included/orderingList.desc.xml 2007-12-03 16:34:35 UTC (rev 4426)
+++ trunk/docs/userguide/en/src/main/docbook/included/orderingList.desc.xml 2007-12-03 16:36:22 UTC (rev 4427)
@@ -19,16 +19,18 @@
<section>
<title>Key Features</title>
<itemizedlist>
- <listitem>Skinnable <property>ordering list</property> and child items</listitem>
- <listitem>Customizable component layout (captions, headers, list items and ordering control set)</listitem>
- <listitem>Disabled/enabled ordering controls</listitem>
- <listitem>Multiple selection in the <property>ordering list</property></listitem>
- <listitem>Possibility to manage selection from
+ <!--listitem>Skinnable <property>ordering list</property> and child items</listitem-->
+ <listitem>Highly customizable look and feel</listitem>
+ <listitem>Reordering and sorting possibilities for list items</listitem>
+ <!--listitem>Customizable component layout (captions, headers, list items and ordering control set)</listitem-->
+ <!--listitem>Disabled/enabled ordering controls</listitem-->
+ <listitem>Multiple selection of list items</listitem>
+ <!--listitem>Possibility to manage selection from
<itemizedlist>
<listitem>Keyboard</listitem>
<listitem>Server side</listitem>
</itemizedlist>
- </listitem>
+ </listitem-->
</itemizedlist>
</section>
</section>
Modified: trunk/docs/userguide/en/src/main/docbook/included/orderingList.xml
===================================================================
--- trunk/docs/userguide/en/src/main/docbook/included/orderingList.xml 2007-12-03 16:34:35 UTC (rev 4426)
+++ trunk/docs/userguide/en/src/main/docbook/included/orderingList.xml 2007-12-03 16:36:22 UTC (rev 4427)
@@ -70,7 +70,7 @@
<para>
<emphasis role="bold">Example:</emphasis>
</para>
- <programlisting role="JAVA"><![CDATA[import org.richfaces.component.html.OrderingList;
+ <programlisting role="JAVA"><![CDATA[import org.richfaces.component.html.HtmlOrderingList;
...
HtmlOrderingList myOrderingList = new HtmlOrderingList();
...]]></programlisting>
@@ -87,7 +87,7 @@
has three different representations for a single element: common, selected,
active. Combination of these states is possible.</listitem>
<listitem>
- <property>ordering controls set</property>
+ <property>Ordering controls set</property>
</listitem>
</itemizedlist>
</para>
@@ -114,7 +114,7 @@
<rich:orderingList value="#{bean.simpleItems}" var="item" selection="#{bean.selection}" controlsType="button">
<rich:column>
<f:facet name="header">
- <h:outputText value="Cars" />
+ <h:outputText value="Cars" />
</f:facet>
<h:outputText value="#{item}" />
</rich:column>
@@ -123,25 +123,24 @@
<para> The <emphasis role="bold">
<property><rich:orderingList></property>
- </emphasis> component provides to use optional<emphasis>
+ </emphasis> component allows to use <emphasis>
<property>"caption"</property>
</emphasis>, <emphasis>
- <property>"header" </property>
- </emphasis>(It's possible to define facet. It has two possible types of
- representation: sortable and non-sortable) facets. </para>
+ <property>"header"</property>
+ </emphasis> and <emphasis>
+ <property>"footer" </property>
+ </emphasis> facets. </para>
<!-- ADD SCREENSHOT-->
-
<para>Simple example is placed below.</para>
<para>
<emphasis role="bold">Example:</emphasis>
</para>
<programlisting role="XML"><![CDATA[...
<rich:orderingList value="#{bean.simpleItems}" var="item" controlsType="button" selection="#{bean.selection}">
- <f:facet name="caption">
- <h:outputText value="Optional Caption Facet" />
- </f:facet>
+ <f:facet name="caption"><h:outputText value="Caption Facet" /></f:facet>
+ <f:facet name="header"><h:outputText value="Header Facet" /></f:facet>
<h:outputText value="#{item}" />
<rich:column>
<f:facet name="header">
@@ -155,13 +154,15 @@
</f:facet>
<h:outputText value="#{item.price}" />
</rich:column>
+ <f:facet name="footer"><h:outputText value="Footer Facet" /></f:facet>
</rich:orderingList>
...]]></programlisting>
<!-- ordering control set-->
<para>The <emphasis role="bold">
<property><rich:orderingList></property>
- </emphasis> component provides the possibility to use <property>ordering controls set</property>, which performs reordering. Every control has possibility to be disabled. </para>
+ </emphasis> component provides the possibility to use <property>ordering controls
+ set</property>, which performs reordering. Every control has possibility to be disabled. </para>
<para>
<emphasis>
<property> "topControl" </property>
@@ -225,7 +226,7 @@
</listitem>
<listitem><emphasis>
- <property> "controlsVerticalAlign" </property>
+ <property> "controlsVerticalAlign"</property>
</emphasis> attribute. Possible values: <itemizedlist>
<listitem>top - controls could be rendered aligned to top side of a list </listitem>
<listitem>bottom - controls could be rendered aligned to bottom side of a
@@ -269,8 +270,7 @@
<para>The component provides possibility to be customized using templating. The
customization could be performed by a layout definition nested into the component. 5
elements are provided to be defined inside template: {list}, {topControl},
- {bottomControl}, {downCotrol}, {upControl}. <para>Thus the markup defined in the initial
- picture could be defined as in the example placed below.</para>
+ {bottomControl}, {downCotrol}, {upControl}. <para>The example is placed below.</para>
</para>
<para>Example:</para>
<programlisting role="XML"><![CDATA[...
@@ -287,7 +287,7 @@
</rich:orderingList>
...]]>
</programlisting>
- <para>The <emphasis role="bold">
+ <!--para>The <emphasis role="bold">
<property><rich:orderingList></property>
</emphasis> component provides the possibility to be customized using templating. The
customization could be performed by layout definition nested to component.</para>
@@ -312,7 +312,7 @@
</h:panelGroup>
</h:panelGrid>
</rich:orderingList>
-...]]></programlisting>
+...]]></programlisting-->
</section>
<table>
16 years, 5 months
JBoss Rich Faces SVN: r4426 - in branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces: component and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: sergeyhalipov
Date: 2007-12-03 11:34:35 -0500 (Mon, 03 Dec 2007)
New Revision: 4426
Added:
branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java
branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/
branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/ListShuttleRenderingTest.java
Removed:
branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
List shuttle rendering JUnit tests.
Part of http://jira.jboss.com/jira/browse/RF-1178
Deleted: branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-12-03 16:02:31 UTC (rev 4425)
+++ branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-12-03 16:34:35 UTC (rev 4426)
@@ -1,53 +0,0 @@
-/**
- * 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 junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import javax.faces.component.UIComponent;
-
-/**
- * Unit test for simple Component.
- */
-public class JSFComponentTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public JSFComponentTest( String testName )
- {
- super( testName );
- }
-
-
- /**
- * Rigourous Test :-)
- */
- public void testComponent()
- {
- assertTrue( true );
- }
-}
Copied: branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java (from rev 4418, branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/JSFComponentTest.java)
===================================================================
--- branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java (rev 0)
+++ branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java 2007-12-03 16:34:35 UTC (rev 4426)
@@ -0,0 +1,56 @@
+/**
+ * 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 org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * Unit test for simple Component.
+ */
+public class ListShuttleComponentTest extends AbstractAjax4JsfTestCase {
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public ListShuttleComponentTest( String testName )
+ {
+ super( testName );
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testComponent()
+ {
+ assertTrue( true );
+ }
+}
Added: branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/ListShuttleRenderingTest.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/ListShuttleRenderingTest.java (rev 0)
+++ branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/renderkit/ListShuttleRenderingTest.java 2007-12-03 16:34:35 UTC (rev 4426)
@@ -0,0 +1,398 @@
+/**
+ * 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.renderkit;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.component.html.HtmlOutputText;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ajax4jsf.resource.InternetResource;
+import org.ajax4jsf.resource.InternetResourceBuilder;
+import org.ajax4jsf.resource.ResourceBuilderImpl;
+import org.ajax4jsf.resource.image.ImageInfo;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
+import org.richfaces.component.UIListShuttle;
+
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+public class ListShuttleRenderingTest extends AbstractAjax4JsfTestCase {
+ private static final int IMAGE_COUNT = 16;
+
+ private UIListShuttle listShuttle = null;
+ private UIForm form = null;
+ private List items = null;
+ private HtmlOutputText output1 = null;
+ private HtmlOutputText output2 = null;
+ private UIColumn column1 = null;
+ private UIColumn column2 = null;
+
+ private static final Set javaScripts = new HashSet();
+ private static final Set imageClasses = new HashSet();
+
+ static {
+ javaScripts.add("org.ajax4jsf.javascript.PrototypeScript");
+ javaScripts.add("scripts/ShuttleUtils.js");
+ javaScripts.add("scripts/SelectItem.js");
+ javaScripts.add("scripts/LayoutManager.js");
+ javaScripts.add("scripts/Control.js");
+ javaScripts.add("scripts/OrderingList.js");
+ javaScripts.add("scripts/extend.js");
+ javaScripts.add("scripts/ListShuttle.js");
+ javaScripts.add("scripts/ListBase.js");
+
+ imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconUp");
+ imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconDown");
+ imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconTop");
+ imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconBottom");
+ imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconUpDisabled");
+ imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconDownDisabled");
+ imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconTopDisabled");
+ imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconBottomDisabled");
+ imageClasses.add("org.richfaces.renderkit.html.gradientimages.OrderingListClickedGradient");
+ imageClasses.add("org.richfaces.renderkit.html.gradientimages.OrderingListHeaderGradient");
+ imageClasses.add("org.richfaces.renderkit.html.gradientimages.OrderingListSelectGradient");
+
+ imageClasses.add("org.richfaces.renderkit.html.images.ListShuttleIconCopy");
+ imageClasses.add("org.richfaces.renderkit.html.images.ListShuttleIconCopyDisabled");
+ imageClasses.add("org.richfaces.renderkit.html.images.ListShuttleIconCopyAll");
+ imageClasses.add("org.richfaces.renderkit.html.images.ListShuttleIconCopyAllDisabled");
+ imageClasses.add("org.richfaces.renderkit.html.images.ListShuttleIconRemove");
+ imageClasses.add("org.richfaces.renderkit.html.images.ListShuttleIconRemoveAll");
+ imageClasses.add("org.richfaces.renderkit.html.images.ListShuttleIconRemoveDisabled");
+ imageClasses.add("org.richfaces.renderkit.html.images.ListShuttleIconRemoveAllDisabled");
+ }
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public ListShuttleRenderingTest(String testName) {
+ super(testName);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ application.addComponent(UIListShuttle.COMPONENT_TYPE, "org.richfaces.component.html.HtmlListShuttle");
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ listShuttle = (UIListShuttle)application.createComponent(UIListShuttle.COMPONENT_TYPE);
+ listShuttle.setId("listShuttle");
+ listShuttle.setVar("item");
+
+ items = new ArrayList();
+ items.add(new SimpleItem("Michael", 2000));
+ items.add(new SimpleItem("John", 500));
+ items.add(new SimpleItem("George", 4000));
+
+ listShuttle.setSourceValue(items);
+
+ output1 = new HtmlOutputText();
+ output1.setValueBinding("value", application.createValueBinding("#{item.name}"));
+ column1 = new UIColumn();
+ column1.getChildren().add(output1);
+ listShuttle.getChildren().add(column1);
+
+ output2 = new HtmlOutputText();
+ output2.setValueBinding("value", application.createValueBinding("#{item.salary}"));
+ column2 = new UIColumn();
+ column2.getChildren().add(output2);
+ listShuttle.getChildren().add(column2);
+
+ form.getChildren().add(listShuttle);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ items = null;
+ output1 = null;
+ output2 = null;
+ column1 = null;
+ column2 = null;
+ listShuttle = null;
+ form = null;
+ }
+
+ /**
+ * Test common rendering
+ *
+ * @throws Exception
+ */
+ public void testCommonRendering() throws Exception{
+ HtmlPage view = renderView();
+ assertNotNull(view);
+ System.out.println(view.asXml());
+
+ HtmlElement table = view.getHtmlElementById(listShuttle.getClientId(facesContext));
+ assertNotNull(table);
+ assertEquals("table", table.getNodeName());
+
+ HtmlElement tbody = (HtmlElement) table.getFirstChild();
+ assertNotNull(tbody);
+ assertEquals("tbody", tbody.getTagName());
+
+ HtmlElement tr = (HtmlElement) tbody.getFirstChild();
+ assertNotNull(tr);
+ assertEquals("tr", tr.getTagName());
+ assertNull(tr.getNextSibling());
+
+ int childCount = 0;
+ for (Iterator it = tr.getChildIterator(); it.hasNext();) {
+ HtmlElement td = (HtmlElement) it.next();
+ assertNotNull(td);
+ assertEquals("td", td.getTagName());
+ childCount++;
+ }
+ assertEquals(4, childCount);
+
+ HtmlElement hidden1 = view.getHtmlElementById(listShuttle.getClientId(facesContext) + "focusKeeper");
+ assertNotNull(hidden1);
+ assertEquals("input", hidden1.getNodeName());
+ assertEquals("button", hidden1.getAttributeValue("type"));
+ hidden1.getAttributeValue("style").contains("left: -32767px");
+
+ List inputs = view.getDocumentElement().getHtmlElementsByAttribute("input", "name", listShuttle.getClientId(facesContext) + "focusKeeper");
+ assertNotNull(inputs);
+ assertEquals(1, inputs.size());
+
+ inputs = view.getDocumentElement().getHtmlElementsByAttribute("input", "name", listShuttle.getClientId(facesContext));
+ assertNotNull(inputs);
+ assertEquals(1, inputs.size());
+ }
+
+ /**
+ * Test script rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderScript() throws Exception {
+ HtmlPage view = renderView();
+ assertNotNull(view);
+ List scripts = view.getDocumentElement().getHtmlElementsByTagName("script");
+ int foundCount = 0;
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ String srcAttr = item.getSrcAttribute();
+
+ if (StringUtils.isNotBlank(srcAttr)) {
+ boolean found = false;
+ for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
+
+ found = srcAttr.contains(src);
+ if (found) {
+ foundCount++;
+
+ String uri = "http:" + srcAttr;
+ Page page = webClient.getPage(uri);
+ assertNotNull(page);
+ assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
+
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+ assertEquals(foundCount, javaScripts.size());
+ }
+
+ /**
+ * Test style rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderStyle() throws Exception {
+ HtmlPage view = renderView();
+ assertNotNull(view);
+ List links = view.getDocumentElement().getHtmlElementsByTagName("link");
+ assertNotNull(links);
+ assertEquals(1, links.size());
+ HtmlElement link = (HtmlElement) links.get(0);
+ assertTrue(link.getAttributeValue("href").contains("css/listShuttle.xcss"));
+
+ String uri = "http:" + link.getAttributeValue("href");
+ Page page = webClient.getPage(uri);
+ assertNotNull(page);
+ assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
+ }
+
+ /**
+ * Test controls rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderControls() throws Exception {
+ HtmlPage view = renderView();
+ assertNotNull(view);
+
+ List images = view.getDocumentElement().getHtmlElementsByTagName("img");
+ assertNotNull(images);
+ assertEquals(IMAGE_COUNT, images.size());
+
+ for (Iterator it = images.iterator(); it.hasNext(); ) {
+ HtmlElement img = (HtmlElement) it.next();
+ assertNotNull(img);
+
+ String uri = "http:" + img.getAttributeValue("src");
+ Page page = webClient.getPage(uri);
+ assertNotNull(page);
+ assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
+
+ HtmlElement div = (HtmlElement) img.getParentNode();
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ div = (HtmlElement) div.getParentNode();
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ div = (HtmlElement) div.getParentNode();
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+ String clazz = div.getAttributeValue("class");
+ assertNotNull(clazz);
+ assertTrue(clazz.contains("rich-shuttle-control"));
+ }
+ }
+
+ /**
+ * Test default images rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderImages() throws Exception {
+ HtmlPage view = renderView();
+ assertNotNull(view);
+
+ InternetResourceBuilder builder = ResourceBuilderImpl.getInstance();
+
+ for (Iterator it = imageClasses.iterator(); it.hasNext(); ) {
+ String clazz = (String) it.next();
+ builder.createResource(null, clazz);
+ InternetResource resource = builder.getResource(clazz);
+ assertNotNull(resource);
+ String uri = "http:" + resource.getUri(facesContext, null);
+ Page page = webClient.getPage(uri);
+ assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
+ ImageInfo info = new ImageInfo();
+ info.setInput(page.getWebResponse().getContentAsStream());
+
+ assertTrue(info.check());
+ assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
+ assertTrue(info.getHeight() > 0);
+ assertTrue(info.getWidth() > 0);
+ }
+ }
+
+ /**
+ * Test items rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderItems() throws Exception {
+ HtmlPage view = renderView();
+ assertNotNull(view);
+
+ HtmlElement div = view.getHtmlElementById(listShuttle.getClientId(facesContext) + "contentBox");
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ HtmlElement table = (HtmlElement)div.getFirstChild();
+ assertNotNull(table);
+ assertEquals("table", table.getNodeName());
+
+ HtmlElement tbody = (HtmlElement)table.getFirstChild();
+ assertNotNull(tbody);
+ assertEquals("tbody", tbody.getNodeName());
+
+ int rowsCount = 0;
+ for (Iterator it = tbody.getChildIterator(); it.hasNext(); ) {
+ HtmlElement tr = (HtmlElement)it.next();
+ assertNotNull(tr);
+ assertEquals("tr", tr.getNodeName());
+
+ String clazz = tr.getAttributeValue("class");
+ assertNotNull(clazz);
+ assertTrue(clazz.contains("rich-shuttle-source-row"));
+
+ int cellsCount = 0;
+ for (Iterator it2 = tr.getChildIterator(); it2.hasNext(); ) {
+ HtmlElement td = (HtmlElement)it2.next();
+ assertNotNull(td);
+ assertEquals("td", td.getNodeName());
+
+ String clazz2 = td.getAttributeValue("class");
+ assertNotNull(clazz2);
+ assertTrue(clazz2.contains("rich-shuttle-source-cell"));
+
+ cellsCount++;
+ }
+ assertEquals(2, cellsCount);
+
+ rowsCount++;
+ }
+ assertEquals(items.size(), rowsCount);
+ }
+
+ protected class SimpleItem {
+ String name;
+ int salary;
+
+ public SimpleItem(String name, int salary) {
+ this.name = name;
+ this.salary = salary;
+ }
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public int getSalary() {
+ return salary;
+ }
+ public void setSalary(int salary) {
+ this.salary = salary;
+ }
+ }
+
+}
16 years, 5 months
JBoss Rich Faces SVN: r4425 - in branches/3.1.x/ui/listShuttle/src/main: resources/org/richfaces/renderkit/html/scripts and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: vmolotkov
Date: 2007-12-03 11:02:31 -0500 (Mon, 03 Dec 2007)
New Revision: 4425
Modified:
branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml
branches/3.1.x/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/scripts/ListShuttle.js
branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx
Log:
dblclick functionality
Modified: branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml 2007-12-03 15:53:06 UTC (rev 4424)
+++ branches/3.1.x/ui/listShuttle/src/main/config/component/listShuttle.xml 2007-12-03 16:02:31 UTC (rev 4425)
@@ -65,7 +65,7 @@
<description>Collection which stores a set of selected items</description>
</property>
- <property>
+ <property>
<name>sourceListWidth</name>
<classname>java.lang.String</classname>
<description>
Modified: branches/3.1.x/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/scripts/ListShuttle.js
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/scripts/ListShuttle.js 2007-12-03 15:53:06 UTC (rev 4424)
+++ branches/3.1.x/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/scripts/ListShuttle.js 2007-12-03 16:02:31 UTC (rev 4425)
@@ -4,19 +4,17 @@
Richfaces.ListShuttle.prototype = {
initialize: function(targetList, sourceList, clientId, controlIds) {
-
sourceList._onclickHandler = sourceList.onclickHandler;
sourceList.onclickHandler = function(e) { this.onclickHandler(e, sourceList); }.bindAsEventListener(this);
targetList._onclickHandler = targetList.onclickHandler;
targetList.onclickHandler = function(e) { this.onclickHandler(e, targetList); }.bindAsEventListener(this);
- //$(targetList.shuttleTable.id).observe("click", function(e) {this.onclickHandler(window.event || e, targetList)}.bindAsEventListener(this));
- //$(sourceList.shuttleTable.id).observe("click", function(e) {this.onclickHandler(window.event || e, sourceList)}.bindAsEventListener(this));
-
-
this.targetList = targetList;
this.sourceList = sourceList;
+ this.targetList.shuttleTable.observe("dblclick", function(e) {this.moveItemByClick(window.event||e, this.targetList, this.sourceList)}.bindAsEventListener(this));
+ this.sourceList.shuttleTable.observe("dblclick", function(e) {this.moveItemByClick(window.event||e, this.sourceList, this.targetList)}.bindAsEventListener(this));
+
this.controlList = new Array();
this.initControlList(clientId, controlIds);
},
@@ -127,6 +125,11 @@
saveState : function() {
this.targetList.saveState();
this.sourceList.saveState();
+ },
+
+ moveItemByClick : function(event, sourceComponent, targetComponent) {
+ var item = this.sourceList.getEventTargetRow(event);
+ this.moveItem(sourceComponent, targetComponent, item);
}
}
Modified: branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx
===================================================================
--- branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx 2007-12-03 15:53:06 UTC (rev 4424)
+++ branches/3.1.x/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx 2007-12-03 16:02:31 UTC (rev 4425)
@@ -40,6 +40,9 @@
SelectionState targetSelectionState = new SelectionState();
variables.setVariable(SELECTION_STATE_VAR_NAME, targetSelectionState);
String encodedTargetRows = encodeRows(context, component, false);
+
+ //boolean switchByClick = (boolean) component.getAttributes().get("switchByClick");
+ //variables.setVariable("switchByClick", switchByClick);
]]>
</jsp:scriptlet>
<table id="#{clientId}" class="rich-list-shuttle">
16 years, 5 months