How to select Multiple items in pickList(Primefaces)?

797 views Asked by At

I am trying to make a pickList. And I want multiple items to get selected on a click of single item. How can I achieve that?

2

There are 2 answers

0
Juan Camilo Mejia On

I´m taking this from the primefaces website in your view, I guess you will have something like this

    <h:form>

     <p:selectBooleanCheckbox value="#{selectBooleanView.value1}" label="parent"> 
        <p:ajax update="cb1 cb2" listener="#{selectBooleanView.yourLogic}" />
      </p:selectBooleanCheckbox>
         <p:selectBooleanCheckbox id="cb1" value="#{selectBooleanView.value2}" label="son1"/> 
         <p:selectBooleanCheckbox id="cb2" value="#{selectBooleanView.value3}" label="son2"/>



    </h:form>

See in the previuos code the ajax tag call the managed bean and update some items based in the ID

Your managed bean SelectBooleanView.java

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

@ManagedBean
public class SelectBooleanView {

private boolean value1;  
private boolean value2;
private boolean value3;

public boolean isValue1() {
    return value1;
}

public void setValue1(boolean value1) {
    this.value1 = value1;
}

public boolean isValue2() {
    return value2;
}

public void setValue2(boolean value2) {
    this.value2 = value2;
}
public boolean isValue3() {
    return value3;
}

public void setValue3(boolean value3) {
    this.value3 = value3;
}

public void yourLogic() {
   this.value3= value1;
   this.value2=value1;
}
}
0
WitYoBadSelf On

You can either use the server side ajax transfer event or client side 'onTransfer' call back attribute.

<p:ajax event="transfer" listener="#{foo.addOtherItemsToTranferList}" />

-OR-

<p:pickList ... onTransfer="foo.bar()">