Search code examples
jsfprimefaces

<p:selectBooleanButton /> always sets the backing bean boolean property to false


I have a list of projects whose contents I am displaying on a web page. Each project has a boolean value to represent if it has been selected. The .xhtml file and the backing bean Project has been given below. The problem is that every time I select or deselect the Boolean button in the webpage it always sets the boolean property in backing bean to false.

.xhtml

<p:outputPanel layout="inline">
  <p:repeat id="projectSelect" 
            value="#{checkoutRulesBean.projectList}" 
            var="project">
    <p:selectBooleanButton id="project"
                            value="#{project.selected}"
                            onLabel="#{project.name}" 
                            offLabel="#{project.name}" 
                            onIcon="fa fa-check"
                            offIcon="fa fa-square-o"
                            style="margin: 5px; padding: 5px;" >

       <p:ajax listener="#{checkoutRulesBean.toggleProjectSelection()}"
             process="@this"
             update="@(.project-boards-table)"/>

    </p:selectBooleanButton>
  </p:repeat>
</p:outputPanel>

Project.java (Backing Bean)

public class Project implements Serializable{
    
    private List<BoardCheckoutRules> boardCheckoutList = new ArrayList<>();
    private Boolean selected = true;
    private String name;
    
    /**
     * Creates a new instance of Project
     */
    public Project() {
    }
    
    public Project(String name){
        this.name = name;
    }


    public List<BoardCheckoutRules> getBoardCheckoutList() {
        return boardCheckoutList;
    }

    public void setBoardCheckoutList(List<BoardCheckoutRules> boardCheckoutList) {
        this.boardCheckoutList = boardCheckoutList;
    }

    public Boolean getSelected() {
        return selected;
    }

    public void setSelected(Boolean clicked) {
        PayaraLogger.logDebug(this.name + " has been " + ((clicked) ? "selected" : "unselected"));
        this.selected = clicked;
    }
   
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }    
}


Solution

  • I found out what the problem was. The selectBooleanButton should be wrapped inside a <h:form>.