0

I have a primefaces datatable and inside the primefaces datatable, I have a column, which contains the . The issue is,I have set the default value for the as false. When I click/check the , its still retrieving the value as false. I tried it multiple times but not sure why its returning false. Please find the sample code below.

  <p:dataTable  id="review-table" var="item" value="#{demandBean.filterVOList}">
  <p:column id="SelectallID" style="text-align: left; width:40px;" rendered="#{demandBean.screeRenderVo.selectAllRenderer}">
 <f:facet name="header" >
  <h:outputText id="selectId"  value="#{demandBean.dmdScreenLabelVO.selectAll}" />
                    <div></div>
<h:selectBooleanCheckbox id="checkbox1" value="Select All" onclick="checkAll(this)"/>
</f:facet>
<h:selectBooleanCheckbox id="checkbox2"  value="#{item.selected}"/>
</p:column>

Im getting the value as false, when I check the and click on the save button. I have written an Action listerner, below is the code corresponding to the actionListener

public void saveData(ActionEvent event)
{
    System.out.println("Entering the Save :");
    selected = isSelected();
    System.out.println("value of Selected"+selected);
}

I have tried debugging the code as well, but not sure why the value for is getting displayed as false. Please Assist. Thanks in Advance

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
vr3w3c9
  • 1,118
  • 8
  • 32
  • 57

1 Answers1

1

You seem to be binding the value of all checkboxes in the column to the one and same bean property. This way the value will ultimately end up to be the one of the last row in the column.

This is not how it's supposed to be used.

You basically need to bind the value of the checkbox to the property of the currently iterated row object (the one behind the var attribute of the datatable).

<p:dataTable value="#{bean.items}" var="item">
    <p:column>
        <p:selectBooleanCheckbox value="#{item.selected}" />

Alternatively, you could use the <p:column selectionMode="multiple" /> to use builtin multiple selection support of the PrimeFaces datatable (see also the showcase example).

<p:dataTable value="#{bean.items}" var="item" rowKey="#{item.id}" selection="#{bean.selectedItems}">
    <p:column selectionMode="multiple" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi Balus, thanks a lot for the response. I have even tried the same. Please find the code that I have edited and updated my post. But still, when I try to select the checkbox, Even if the checkbox is selected, it returns a false value. Also I dont want to use the primefaces selection mode, since the styles are different compared to the ordinary . – vr3w3c9 Aug 02 '12 at 05:52
  • That could happen when the `rendered` attribute of the `` has evaluated `false` during processing the form submit. There's by the way another way than binding the value to a property of the item; binding it by the item identifier to a `Map`, see also http://stackoverflow.com/questions/2524514/how-to-use-jsfs-hselectbooleancheckbox-with-hdatatable-to-create-one-object-p/2524832#2524832 (note that this won't solve the "false" value problem, it's merely another design approach). – BalusC Aug 02 '12 at 11:03
  • @BalusC I'm having the same problem, but using , the bean is called but the method not... can you help me? –  Dec 12 '13 at 11:37