Reputation: 11
Is it necessary to use a converter when working with pickList
? Well, here's my code:
<p:pickList value="#{usuarioBean.listaMembros}" var="#{usuario}" itemLabel="#{usuario.nome}">
<f:facet name="cadastrados">Membros</f:facet>
<f:facet name="equipe">Membros da Equipe</f:facet>
</p:pickList>
All I keep getting is:
java.util.ArrayList cannot be cast to org.primefaces.model.DualListModel
Upvotes: 1
Views: 3410
Reputation: 643
Your picklist needs to point to a DualListModel...which itself contains a source list and a target list. So you need to create a source list and a target list and then create a DualListModel from them e.g. taking the primefaces showcase example:
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"));
listaMembros = new DualListModel<Player>(source, target);
Then your getter and setter would get and set a DualListModel...e.g
public DualListModel<Player> getListaMembros() {
return listaMembros;
}
public void setPlayers(DualListModel<Player> players) {
this.listaMembros = listaMembros;
}
Then in your xhtml the value of your picklist would be
#{usarioBean.listaMembros}
If your data within your lists is a complex type then you'll need to use a converter to convert the object
Upvotes: 5