Batakj
Batakj

Reputation: 12743

how to prepopulate target in Primefaces picklist?

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.

Upvotes: 0

Views: 1594

Answers (3)

Surya Mandal
Surya Mandal

Reputation: 159

add belwo code

 citiesTarget.add("Value1");
  citiesTarget.add("value2");

Upvotes: 0

Ioan
Ioan

Reputation: 5187

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.

Upvotes: 1

zargarf
zargarf

Reputation: 643

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

Upvotes: 1

Related Questions