【问题标题】:Primefaces, activeindex listener not calling in multiple tabsPrimefaces,activeindex侦听器未在多个选项卡中调用
【发布时间】:2012-03-28 08:28:18
【问题描述】:

您好,我使用的是 primefaces 3.2 版,我使用的 ui 布局是 tabview,在其中,我有手风琴面板,在手风琴的每个选项卡内,我有两种形式。

就像 tabview>tab>accordionpanel>tab>form1 和

tabview>tab>accordionpanel>tab>form2 等等...

现在,问题是在上述场景中没有调用活动索引操作。但是,当我从手风琴面板选项卡中删除一个 froms 时,它会被调用并且工作正常。

这是我的 xhtml tabview 代码

    <p:tabView id="tabView" activeIndex="#{profileInfoManagedBean.myCurrentTab}" >
        <p:ajax event="tabChange" listener="#{profileInfoManagedBean.tabIsChanged}" />

        <p:tab id="locationInfoTab" title="Location Info">

            <p:accordionPanel id="aPanel">

                <p:tab id="tab1" title="Country">
                    <h:form id="form1">
                        <p:growl id="growl" life="5000" />

                        <p:messages id="messages"  /> 

                        <h:panelGrid columns="3" cellpadding="5" cellspacing="5">

                            <p:column>
                                <h:outputLabel for="country"  value="Country: "></h:outputLabel>
                            </p:column>
                            <p:column>
                                <p:inputText id="country" value="#{profileInfoManagedBean.country.country}" required="true" label="City">

                                    <f:validateLength minimum="5" maximum="20" />
                                    <p:ajax event="blur" update="msg1"></p:ajax>
                                </p:inputText>
                            </p:column>
                            <p:column>
                                <p:message id="msg1" for="country" display="icon"></p:message>
                            </p:column>

                        </h:panelGrid>
                        <p:commandButton type="submit" action="#{profileInfoManagedBean.addCountry}" value="Save" ajax="true" ></p:commandButton>

                    </h:form>

【问题讨论】:

    标签: primefaces accordion tabview


    【解决方案1】:

    您想要在 locationInfoTab 上还是在手风琴 tab1 上的活动索引?

    我对您的代码进行了一些测试和修改,以获得两者的活动索引:

    <h:form id="tabViewForm">
    
    <p:tabView id="tabView" activeIndex="#{profileInfoManagedBean.myCurrentTab}" >
      <p:ajax event="tabChange" listener="#{profileInfoManagedBean.tabIsChanged}" update=":tabViewForm"/>
      <p:tab id="locationInfoTab" title="Location Info">
          <p:accordionPanel id="aPanel" activeIndex="#{profileInfoManagedBean.myCurrentAccordionTab}">
            <p:ajax event="tabChange" listener="#{profileInfoManagedBean.tabIsChanged}" update=":tabViewForm" />
            <p:tab id="tab1" title="Country">
              <h:form id="form1">
    .
    .
    .
    <p:inputText id="country" value="#{profileInfoManagedBean.country.name}" required="true" label="Country">
      <f:validateLength minimum="5" maximum="20" />
      <p:ajax event="blur" update="country msg1 growl messages"></p:ajax>
    </p:inputText>
    .
    .
    .
      </p:accordionPanel>
    </p:tab>
    <p:tab id="tab2" title="Tab Information">
    </p:tab>
    </p:tabView>
    </h:form>
    

    我在手风琴面板中添加了选项卡更改事件,在选项卡更改时更新 tabViewForm,在输入更改时更新消息,并添加了另一个选项卡进行测试。

    我认为最初的问题是由于输入字段上的验证器导致错误,但视图没有更新以向您显示消息。

    通过在选项卡更改时更新表单,验证器错误消息清晰可见。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-02
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 2015-09-03
      • 1970-01-01
      相关资源
      最近更新 更多