-
1. Re: RF 4.2 - pickList doesn't use value attribute
iabughosh Mar 6, 2012 4:20 AM (in response to pczekaj)hello Piotr,
relax Piotr, it is not a bug , I'll explain in details :
if you have this .xhtml code:
<rich:pickList id="yourList"
value="#{yourBean.selectedItems}"
listHeight="120px"
listWidth="100px">
<f:selectItems value="#{yourBean.availableItems}"
var="item"
itemLabel="#{item.name}"
itemValue="#{item.id}"/>
</rich:pickList>
then the value attribute in the rich:pickList needs to be a collection of primitive type or String (ex:List<String>, List<Integer>), and itemValue attr at f:selectItems needs to be of a type String, int (as pickList value type).
RichFaces show case was able to set List<CustomObjects> in the value attribute because they were using FacesConverter named "CapitalsConverter".
regards.
-
2. Re: RF 4.2 - pickList doesn't use value attribute
pczekaj Mar 6, 2012 8:53 AM (in response to iabughosh)Thanks for response but even for strings pickList doesn't work as I would expect. Below image shows how page looks like in browser when first loaded, looking at init method it should show "Item 4" and "Item 5" on the right.
Bean code:
package example; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.annotation.PostConstruct; import javax.ejb.Stateful; import javax.enterprise.context.SessionScoped; import javax.inject.Named; @Named @SessionScoped @Stateful public class PickList implements Serializable { private List<String> freeItems = new ArrayList<String>(); private List<String> selectedItems = new ArrayList<String>(); @PostConstruct public void init() { freeItems.add("Item 1"); freeItems.add("Item 2"); freeItems.add("Item 3"); selectedItems.add("Item 4"); selectedItems.add("Item 5"); } public String save() { System.err.println(selectedItems); return null; } public List<String> getFreeItems() { return freeItems; } public void setFreeItems(List<String> freeItems) { this.freeItems = freeItems; } public List<String> getSelectedItems() { return selectedItems; } public void setSelectedItems(List<String> selectedItems) { this.selectedItems = selectedItems; } }
Facelets:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a="http://richfaces.org/a4j" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:rich="http://richfaces.org/rich"> <h:head></h:head> <h:body> <h:form> <rich:messages /> <rich:pickList value="#{pickList.selectedItems}" var="item" orderable="true"> <rich:column> <h:outputText value="#{item}"></h:outputText> </rich:column> <f:selectItems value="#{pickList.freeItems}" var="item" itemLabel="#{item}" itemValue="#{item}"/> </rich:pickList> <a:commandButton action="#{pickList.save}" value="Save" /> </h:form> </h:body> </html>
-
3. Re: RF 4.2 - pickList doesn't use value attribute
iabughosh Mar 6, 2012 9:07 AM (in response to pczekaj)add also item 4 and item 5 to the free items, free items must contain all the items, selected or not.
-
4. Re: RF 4.2 - pickList doesn't use value attribute
pczekaj Mar 7, 2012 3:19 AM (in response to iabughosh)Thank you for you help, rich:pickList works as expected for both collection of strings and also my custom objects. Adding all elements to "freeItems" helped, that's the difference between using RF 3.3 rich:listShuttle and RF 4.2 rich:pickList.