Primefaces SelectBoolean复选框在表单提交时未选中



我是这个网站的新手,我的问题与素数中的选择布尔复选框有关。每当我提交表单时,该复选框都会被取消选中。我正在使用动态选项卡视图。

这是我的 xhtml 代码:-

<h:form id="form" >
<p:panel id="tagsPanel" >
<p:tabView id="tabView"  style="background-color:transparent;background-image:none;" var="tabKey" value="#{MBean.Names}"  
      dynamic="true"  >
<p:dataGrid var="appSettingsList"  value="#{appSettingsMBean.tabData[tabKey]}"    columns="1" styleClass="plainDataGrid">
    <h:panelGrid columns="2"  border="0" cellspacing="0" cellpadding="0"  columnClasses="JspContent12 ,JspContent22"  width="100%" >
         <p:column escape="false" >  
<p:selectBooleanCheckbox value="#{appSettingsList.resultValues.checkboxValue}"   style="float:left" id="checkBoxValue"
                     rendered="#{appSettingsList.currentValues != null and appSettingsList.currentValues.size() > 0 and
                      appSettingsList.displayType.equalsIgnoreCase('single') and appSettingsList.dataType.equalsIgnoreCase('boolean')}">
                     </p:selectBooleanCheckbox>
           </p:column>
        </h:panelGrid>
    </p:dataGrid>   
</p:panel>
          <p:panel border="0" id="buttonRow" style="text-align:center;border-width:0;border-style:none;background-image:none;" >           
        <p:commandButton  value="Save"   id="save"  actionListener="#{MBean.saveSettings()}" ajax="false" style="width:130px" />
</p:panel>
</h:form>

更改选项卡并单击保存 btn 时,复选框保持选中状态但是,当仅单击保存btn时,它将被取消选中
任何帮助将不胜感激...

在这里,

<p:commandButton ... ajax="false" />

Ajax 已关闭。因此,提交表单后将执行整页刷新。未选中该复选框表明 Bean 没有正确保持其状态,或者您正在 getter 方法中执行业务逻辑,这会导致它每次都返回一个新的新模型,而不是保存提交值的模型。

您有 2 个选项:

  1. 只需使用ajax.即摆脱ajax="false"。如果您打算在提交时更新视图的某些部分,则只需相应地指定update属性即可。

  2. 确保你的豆子不会弄乱状态或getter。

最新更新