3

我的p:tabView组件存在严重问题。我已经设置dynamic="true"cache="false"tabView。其中一个选项卡具有一些已设置的输入组件required="true"

现在,当我每次更改选项卡时,都会进行表单验证,并且 FacesMessages 正在咆哮中显示。

这是标签:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:f="http://java.sun.com/jsf/core"
   xmlns:p="http://primefaces.org/ui"
   template="/WEB-INF/templates/globalTemplate.xhtml">

   <ui:define name="title">#{adbBundle['home']}</ui:define>
   <ui:define name="content">
      <p:growl id="growl" showDetail="true" autoUpdate="true" />

      <p:tabView id="adminTabView" dynamic="true" cache="false">
         <p:tab title="#{adbBundle['admin.customerTab.title']}"
            id="customerTab">
            <ui:include src="/WEB-INF/includes/adminCustomer.xhtml" />
         </p:tab>
         <p:tab title="#{adbBundle['admin.activityTab.title']}"
            id="activityTab">
            <ui:include src="/WEB-INF/includes/addActivity.xhtml" />
         </p:tab>
      </p:tabView>

   </ui:define>

</ui:composition>

adminCustomer.xhtml 包含表单,它是:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:f="http://java.sun.com/jsf/core"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:p="http://primefaces.org/ui">

   <h:form id="customerForm">
      <p:panel id="addCustomerPanel" toggleable="true"
         header="#{adbBundle['admin.addCustomerPanel.header.new']}">
         <p:panelGrid columns="2" id="addCustomerTable"
            styleClass="addCustomerTable">
            <f:facet name="header">
               <p:outputLabel id="header"
                  value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.header']}" />
            </f:facet>

            <p:outputLabel for="customerName"
               value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerName']}" />
            <h:panelGroup layout="block">
               <p:inputText id="customerName" styleClass="customerName"
                  autocomplete="off"
                  label="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerName']}"
                  value="#{adminController.customerDTO.customerName}"
                  required="true" />               
            </h:panelGroup>

            <p:outputLabel for="customerId"
               value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerId']}" />
            <h:panelGroup layout="block">
               <p:inputText id="customerId" autocomplete="off"
                  label="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerId']}"
                  value="#{adminController.customerDTO.customerId}" required="true">
                  <f:validator validatorId="customerIDValidator" />
               </p:inputText>               
            </h:panelGroup>

            <p:outputLabel for="activeStatus"
               value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.activeStatus']}" />
            <h:panelGroup layout="block">
               <p:selectBooleanCheckbox id="activeStatus"
                  value="#{adminController.customerDTO.active}" />
            </h:panelGroup>

            <f:facet name="footer">
               <p:commandButton value="#{adbBundle['saveButton']}"
                  actionListener="#{adminController.saveCustomer}"
                  icon="ui-icon-check"
                  update=":growl, @form" />
            </f:facet>
         </p:panelGrid>
      </p:panel>
   </h:form>

</ui:composition>

我无法找到我做错了什么以及如何解决它。我正在使用 Primefaces 3.4.2 和 JSF Mojarra 2.1.7-jbossorg。任何指针都会对我很有帮助。

我也在 PrimeFaces 论坛上问过这个问题。

4

2 回答 2

4

这是如何tabView工作的。以下是 PrimeFaces 跟踪器的相关问题:

如您所见,第一个标记为 WontFix。第二个是重复的,但最后你会看到另一个解决方法

如果您仔细阅读该线程,您可能会注意到一些解决方法仍然存在。如果您被迫使用其中一种,请尝试其中一种tabView。如果您想在不同的选项卡中使用输入,还可以考虑使用PrimeFaces - Wizard 。

于 2012-12-26T06:03:04.740 回答
0

如果我正确理解您的问题,实际上有一个非常简单的解决方法可以防止重复显示消息。

将您的咆哮更改为以下内容:

<p:growl id="growl" globalOnly="true" autoUpdate="true" showDetail="true" />

如果您想从支持 bean 端添加消息,您可以使用以下代码执行此操作:

FacesContext.getCurrentInstance()
   .addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "title", "details");

如果你想完全安全,你甚至可以为咆哮指定一个 for 属性,并将其作为第一个参数addMessage

于 2014-08-14T08:31:06.920 回答