简体   繁体   English

的价值 <h:selectBooleanCheckbox> 内 <p:dataTable> 提交时仍为假

[英]Value of <h:selectBooleanCheckbox> inside <p:dataTable> remains false on submit

I have a primefaces datatable and inside the primefaces datatable, I have a column, which contains the . 我有一个primefaces数据表,而在primefaces数据表中,我有一列,其中包含。 The issue is,I have set the default value for the as false. 问题是,我已将的默认值设置为false。 When I click/check the , its still retrieving the value as false. 当我单击/选中时,它仍会检索为false的值。 I tried it multiple times but not sure why its returning false. 我尝试了多次,但不确定为什么返回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. 当我检查并单击保存按钮时,我将值获取为false。 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. 我也尝试调试代码,但不确定为什么值显示为false。 Please Assist. 请协助。 Thanks in Advance 提前致谢

You seem to be binding the value of all checkboxes in the column to the one and same bean property. 您似乎将列中所有复选框的值绑定到one and same bean属性。 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). 基本上,您需要将复选框的值绑定到当前迭代的行对象的属性(数据表的var属性后面的属性)。

<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:column selectionMode="multiple" />来使用PrimeFaces数据表的内置多选支持( 另请参见示例示例 )。

<p:dataTable value="#{bean.items}" var="item" rowKey="#{item.id}" selection="#{bean.selectedItems}">
    <p:column selectionMode="multiple" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM