简体   繁体   English

如何在Primefaces选项列表中预填充目标?

[英]how to prepopulate target in Primefaces picklist?

How to populate the target in Primefaces picklist? 如何在Primefaces选项列表中填充目标? 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. 管理员可以将选定的播放器取消分配(目标 - >源),反之亦然。

Follow the example on the showcase: http://www.primefaces.org/showcase/ui/picklist.jsf 按照展示的例子: 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 如果您只需要根据用户角色显示目标或源控制箭头,那么您可以将showSourceControls和showTargetControls绑定到managedbean中的方法,该方法返回字符串“true”或“false”,具体取决于用户角色

I think the showcase which zargarf mentioned is quite enough to populate the target. 我认为zargarf提到的展示足以填充目标。 If you look over the constructor of the bean, there are sources populated. 如果查看bean的构造函数,则会填充源。 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. 希望这可以帮助。

add belwo code 添加贝尔沃代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM