validation - Primefaces tabView 在选项卡更改时执行表单验证

标签 validation jsf-2 primefaces onchange tabview

我的 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 论坛上问过这个问题。

最佳答案

这就是tabView 的工作原理。以下是 PrimeFaces 跟踪器的相关问题:

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

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

关于validation - Primefaces tabView 在选项卡更改时执行表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14010537/

相关文章:

ios - Xcode提交到应用商店的问题

jsf - 如何使用依赖对象关系更新多个组件(selectOneMenu)?

PHP MySQL JQuery 表单无法在客户端验证

ios - IOS 7中的电子邮件地址验证

java - PrimeFaces v3.5 : Dialog is not shown using RequestContext on non-Ajax calls

java - JSF 2.1 重定向到 portlet

javascript - 如何使用 Primefaces 向导 onnext 属性执行 Javascript 函数?

jsf-2 - ManagedBean 参数未被接受且 Bean 似乎不在范围内

jsf - List<T> 上的 UISelectMany 导致 java.lang.ClassCastException : java. lang.String 无法转换为 T

javascript - 验证不以特殊字符开头或结尾的文本框