0

I'm using PrimeFaces' pickList component in my project. But the problem is the the action function is never called.

<p:pickList id="pickList" value="#{pickListBean.names}" var="name"
    itemLabel="#{name}itemValue="#{name}" />
<p:commandButton ajax="false" id="submit" value="Submit" type="submit"
    action="#{pickListBean.performAction}" />

My managed bean is given in the following:

@ManagedBean(name="pickListBean")
@SessionScoped
public class PickListBean {
private DualListModel<String> names;
private List<String> nam1;
private List<String> nam2;

public PickListBean() {
    nam1 = new ArrayList<String>();
    nam2 = new ArrayList<String>();

    nam1.add("Ammar");
    nam1.add("Nisar");
    nam1.add("Khalid");
    nam1.add("Haris");
    nam1.add("Yasir");

    names = new DualListModel<String>(nam1, nam2);
}

public DualListModel<Player> getPlayers() {
    return players;
}
public void setPlayers(DualListModel<Player> players) {
    this.players = players;
}

public DualListModel<String> getNames() {
    return names;
}
public void setNames(DualListModel<String> names) {
    this.names = names;
}

public String performAction()
{
    for (Iterator iterator = nam2.iterator(); iterator.hasNext();) {
        String name = (String) iterator.next();
        System.out.print("\t" + name);
    }
    return "";
}

}

I'll be thankful for help.

Ammar
  • 1,811
  • 5
  • 26
  • 60
  • Is this just a typo ? : `itemLabel="#{name}itemValue="#{name}"`. You are missing a double quote and a space after `"#{name}here` in `itemLabel`. If it is a typo add `` to your .xhtml to check for errors. – Fallup May 19 '12 at 12:43

3 Answers3

0

First of all, are the picklist and command button nested within a form? to check if action works take println out of for loop as it may be that u never get there

public String performAction() {

    System.out.println("works");

}

Bogdan Glosz
  • 107
  • 2
  • 8
0

To get selected values use names.getTarget() and get a list of the selection.

Ammar
  • 1,811
  • 5
  • 26
  • 60
  • Yeah, there is. But it doesn't works for custom types. A converter a is required to handle such types. But I'm unable to write a correct a converter for pick list. Any help in this regard? – Ammar May 21 '12 at 12:35
0

Ok then! so the problem is not as u identified as your action button works , and you would like to know how to retrieve the data from the dual list, did I understand correctly? If so then to get each position in the dual list you will have to

public void performAction(){
      String sor;
      String tar;
      sor=names.getSource().get(i);
      tar=names.getTarget().get(i);
      System.out.println("works"+sor+tar);

  }

Where i is the number of current position in the list from upper side (so if i=0 u get most top position of each list) With simple for loop u can iterate to get all the entries. Also if u need to use the iterator I think u could use names.getSource().iterator() and the same for the getTarget(). Besides the iterator I tried the above solution and it worked so I hope it helps you.

Bogdan Glosz
  • 107
  • 2
  • 8