I am a newbee for Richfaces components, When i am using the <rich:listShuttle> the Arraylist specified in the targetValue is now getting updated with the latest data?
Kindly help
MyJSF File
<a4j:region>
<rich:listShuttle sourceValue="#{bean.selectItems}" id="one"
targetValue="#{bean.selectItemsone}" var="items" listsHeight="150"
sourceListWidth="130" targetListWidth="130"
sourceCaptionLabel="Intial Items"
targetCaptionLabel="Selected Items" converter="Listconverter">
<rich:column>
<h:outputText value="#{items.value}"></h:outputText>
</rich:column>
</rich:listShuttle>
</a4j:region>
<a4j:region>
<a4j:commandButton value="Submit" action="#{bean.action}" />
</a4j:region>
My Managed Bean
enter code here
private List<String> selectedData;
private List<BeanItems> selectItems;
private List<BeanItems> selectItemsone;
public String action() {
System.out.println(selectItems);
System.out.println(selectItemsone);
System.out.println("Select Item List");
Iterator<BeanItems> iterator = selectItems.iterator();
while (iterator.hasNext()) {
BeanItems item = (BeanItems) iterator.next();
System.out.println(item.getValue());
}
System.out.println("/nSelect Item one list ");
Iterator<BeanItems> iterator2 = selectItemsone.iterator();
while (iterator2.hasNext()) {
BeanItems item = (BeanItems) iterator2.next();
System.out.println(item.getValue());
}
return "";
}
public void setSelectedData(List<String> selectedData) {
this.selectedData = selectedData;
}
public List<String> getSelectedData() {
return selectedData;
}
/**
* @return the selectItems
*/
public List<BeanItems> getSelectItems() {
if (selectItems == null) {
selectItems = new ArrayList<BeanItems>();
selectItems.add(new BeanItems("value4", "label4"));
selectItems.add(new BeanItems("value5", "label5"));
selectItems.add(new BeanItems("value6", "label6"));
selectItems.add(new BeanItems("value7", "label7"));
selectItems.add(new BeanItems("value8", "label8"));
selectItems.add(new BeanItems("value9", "label9"));
selectItems.add(new BeanItems("value10", "label10"));
}
return selectItems;
}
/**
* @return the selectItemsone
*/
public List<BeanItems> getSelectItemsone() {
if (selectItemsone == null) {
selectItemsone = new ArrayList<BeanItems>();
selectItemsone.add(new BeanItems("value1", "label1"));
selectItemsone.add(new BeanItems("value2", "label2"));
selectItemsone.add(new BeanItems("value3", "label3"));
}
return selectItemsone;
}
My Converter Class
enter code here
public Object getAsObject(FacesContext context, UIComponent component,String value) {
int index = value.indexOf(':');
return new BeanItems(value.substring(0, index), value.substring(index + 1));
}
public String getAsString(FacesContext context, UIComponent component,Object value) {
BeanItems beanItems = (BeanItems) value;
return beanItems.getValue() + ":" + beanItems.getData();
}
My BeanItems Class
enter code here
private String data; //Getter & setter
private String value; //Getter & setter
public BeanItems() {
}
public BeanItems(String value, String data) {
this.value = value;
this.data = data;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((data == null) ? 0 : data.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final BeanItems other = (BeanItems) obj;
if (data == null) {
if (other.data != null)
return false;
} else if (!data.equals(other.data))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}