views:

5031

answers:

6

I am using a Richfaces' picklist and I want to populate the right-side panel with a list of SelectItems from my backing bean.

Populating the left-side is not a problem from the backing bean, however, the right hand side is problematic.

This is what I currently have

<h:outputText value="Roles" />
<rich:pickList showButtonsLabel="false">
    <f:selectItems value="#{Bean.allRoles}" />
</rich:pickList>

EDIT:

So I have roles 'a', 'b', 'c', and 'd'.

The user has roles 'a' and 'd', so 'a' and 'd' should be on the right-side panel and 'b' and 'c' should be on the left-side panel.

EDIT:

Further explanation.

I have three lists for the user.

  1. All posible roles (a thru d)
  2. All roles the user is part of (a and d)
  3. All roles the user is NOT part of (b and c)

All lists have the data type ArrayList<SelectItem>.

I need the capability to move individual roles between list number 1 and list number 2 and then save the new set of roles. I thought the picklist would be the best richfaces object for the job.

A: 

Set the value of the pickList to an array of the value of the SelectItem.

Whatever you start out with on the right hand side will then basically just be the default value of the pickList:

    <rich:pickList value="#{aBean.rightSideValues}"> 
        <f:selectItems value="#{aBean.leftSideValues}"/>
    </rich:pickList>
Zack
i am trying it out...i am getting an error: java.lang.IllegalArgumentException: Value is not Stringthanks and i keep trying new things.
Berek Bryan
Sorry. You actually want it to be the *value* of the selectItem, not the selectItem itself.
Zack
+1  A: 

You want this code:

<h:outputText value="Roles" />
<rich:pickList showButtonsLabel="false" value="#{bean.chosenRoles}">
    <f:selectItems value="#{Bean.allRoles}" />
</rich:pickList>

and in your bean you want:

private String[] chosenRoles;

+ getter/setter

Whenver you want to make default roles you just add the roles into the chosenRoles array (for example in the bean constructor). That way chosenRoles will always contain the elements on the right side of the picklist, while elements on the left side are not in the array.

Hope this helps!

ChrisAD
A: 

How do you retrieve the aBean.rightSideValues in the Backing bean. I mean tried putting them as Array list of SelectItem and printing out the values , it did NOT work. I then tried List of Strings, and I also tried String array. None worked.

My default object is of type Faculty(Entity object). I converted from List of Faculty to List of SelectItem to display the list on the leftSideValues. Now how do I access the picked List results which come on to the right side. What type will they be.

Please let me know.

Sai
A: 

plz did u find a solution for ure problem cuz i have the same one!! did u know how to get back in ure bean values of the picklist rightside???

doudia
+1  A: 
indegro
A: 

If you need values other than text, you need to make a converter.

See http://programmingnutsandbolts.blogspot.com/2009/08/richfaces-picklist-converters.html

Ivar Wedøe