Question

How to populate the target in Primefaces picklist? I googled it but i didn't find any example related to this which help my requirement.

I have list of players which is already selected and unassigned. I want to use picklist. Source display the unassigned and target will show the selected one. Admin can make selected player unassigned (target->source) and vice versa.

Était-ce utile?

La solution

I think the showcase which zargarf mentioned is quite enough to populate the target. If you look over the constructor of the bean, there are sources populated. In the same way you can populate the targets.

Currently in the constructor is :

  //Players  
    List<Player> source = new ArrayList<Player>();  
    List<Player> target = new ArrayList<Player>();  

    source.add(new Player("Messi", 10, "messi.jpg"));  
    source.add(new Player("Iniesta", 8, "iniesta.jpg"));  
    source.add(new Player("Villa", 7, "villa.jpg"));  
    source.add(new Player("Alves", 2, "alves.jpg"));  
    source.add(new Player("Xavi", 6, "xavi.jpg"));  
    source.add(new Player("Puyol", 5, "puyol.jpg"));      

    players = new DualListModel<Player>(source, target); 

Do in the same way with the target. target.add(...)

Hope this helps.

Autres conseils

Follow the example on the showcase: http://www.primefaces.org/showcase/ui/picklist.jsf

If you need to only show either target or source control arrows based on user role then you can bind showSourceControls and showTargetControls to a method in the managedbean that returns a string of "true" or "false" depending on the user role

add belwo code

 citiesTarget.add("Value1");
  citiesTarget.add("value2");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top