【问题标题】:Primefaces SelectBooleanCheckbox gets unchecked on form submissionPrimefaces SelectBooleanCheckbox 在提交表单时未选中
【发布时间】:2015-01-29 20:56:15
【问题描述】:

我是这个网站的新手 我的问题与 primefaces 中的 SelectBooleanCheckbox 有关。 每当我提交表单时,复选框都会被取消选中。 我正在使用动态标签视图。

这是我的 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时,复选框仍保留检查 但是,当只点击保存按钮时,它会被取消选中
任何帮助将不胜感激...

【问题讨论】:

标签: jsf primefaces jsf-2.2


【解决方案1】:

这里,

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

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

你有两个选择:

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

  2. 确保您的 bean 不会与 state 或 getter 混淆。

【讨论】:

  • 感谢您的回复@BalusC,但是,我没有弄乱吸气剂。此外,当我只是更改并单击提交选项卡而不进行任何其他操作时,复选框的状态仍然存在
  • 它只在 Form 任务中变为空,没有任何操作。会不会是因为 TabView 动态 = true
猜你喜欢
  • 2013-04-03
  • 1970-01-01
  • 1970-01-01
  • 2013-01-21
  • 2014-05-24
  • 1970-01-01
  • 2017-02-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多