【问题标题】:Selected values of selectBooleanCheckbox and selectoneradio is reset while navigating between tabs of tabviewselectBooleanCheckbox 和 selectoneradio 的选定值在 tabview 的选项卡之间导航时被重置
【发布时间】:2016-06-30 11:39:28
【问题描述】:

我正在尝试通过使用 primefaces 来创建一个带有几个选项卡的页面。但是在选项卡之间导航时,一些选定的值会丢失。最后一个选项卡包含 2 个 selectBooleanCheckboxes 和 2 个 selectOneRadios,其中一个 selectoneradio 网格根据复选框值呈现。当用户在这 4 个组件中进行选择并在选项卡单选按钮和复选框之间导航时,所选值将丢失。我在 bean 部分使用@viewScoped。例如,如果用户正在查看第四个选项卡并想从第三个选项卡更改某些内容。当用户导航到第三个选项卡并对复选框或单选按钮进行更改时,新值和以前的值将被重置。我认为表单正在再次上传。为什么价值会丢失?有解决方案吗?我需要转换器之类的东西吗?

我的 .xhtml 是:

   <h:form id="form">
        <p:tabView id="tabPanel" dynamic="true" activeIndex="#{myBean.activeIndex}" cache="false">

            <!-- FIRST TAB -->
            <p:tab id="person" title="Person">
                <h:panelGrid columns="2" cellpadding="10">              
                    <h:outputText value="name" />
                    <p:inputText value="???USERINFO???" label="Name" />
                    <p:commandButton  value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />
                </h:panelGrid>
            </p:tab>                     

            <!-- SECOND TAB -->
            <p:tab id="adres" title="Address">
                <h:panelGrid columns="2" cellpadding="10">
                    <h:outputText value="Phone" />
                    <p:inputMask id="phone" value="???USERINFO???" mask="1999999999" required="true" requiredMessage="ERROR AT PHONE NUMBER"/>
                    <p:commandButton  value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />
                </h:panelGrid>
            </p:tab>

            <!-- THIRD TAB -->
            <p:tab id="contact" title="Contact">
                <h:panelGrid columns="2" cellpadding="10">


     <h:panelGrid columns="3" style="margin-bottom:5px" cellpadding="5">
   <h:outputText value="My Question: " />
        <p:selectBooleanCheckbox value="#{myBean.myCheckBox}" />
        <h:outputText value="Yes" />                     
        <h:outputText value="My Second Question:" />
        <p:selectBooleanCheckbox value="#{myBean.myCheckBox2}" />
        <h:outputText value="No" /> 
     </h:panelGrid>                           

     <h:panelGrid id="panelGrid" columns="3" style="margin-bottom:10px" cellpadding="10">
 <p:outputLabel value="My question"/>
  <h:outputLabel for="radio"/>
  <h:selectOneRadio id="radio" value="#{myBean.radioButton}" required="true" requiredMessage="ERROR">
      <f:selectItem itemLabel="Yes" itemValue="Yes"/>
      <f:selectItem itemLabel="No" itemValue="No"/>
    <f:ajax execute="@this" render="idInfo"/>
     </h:selectOneRadio>
     </h:panelGrid>                 

                        <h:panelGroup id="idInfo">
                        <h:panelGrid columns="3" rendered="#{myBean.radioButton == 'No'}">
                        <h:outputText value="Chooses: " />
                        <h:selectOneRadio id="selectOneRadio" value="#{myBean.type}" layout="pageDirection">
                            <f:selectItem itemLabel="Choice 1" itemValue="choice1"/>
                            <f:selectItem itemLabel="Choice 2" itemValue="choice2"/>
                            <f:selectItem itemLabel="Choice 3" itemValue="choice3"/>
                         </h:selectOneRadio>
                        </h:panelGrid>  
                        </h:panelGroup>     
                </h:panelGrid>
            </p:tab>             

        </p:tabView>
    </h:form>

【问题讨论】:

    标签: jsf primefaces tabview selectoneradio selectbooleancheckbox


    【解决方案1】:
    <p:commandButton  value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />
    

    将进程添加到按钮的process=":form:tabPanel",以便将值设置为 backbean 中的属性。

    【讨论】:

    • 我在最后一个标签按钮上试过这个,但没有改变。
    • 为什么 ajax="false"?并尝试 process="@this :form:tabPanel"
    • 我试过了,但我得到了这个错误:1100:找不到标识符为“@this:form:tabPanel”的组件,该标识符引用自“tabPanelInst:j_idt250”。 javax.faces.FacesException:找不到从“tabPanel:j_idt250”引用的标识符为“@this:form:tabPanel”的组件
    猜你喜欢
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    相关资源
    最近更新 更多