Primefaces tabView executes form validation on tab change
的输入组件。
现在,当我每次更改选项卡时,都会进行表单验证,并且FacesMessages将显示在咆哮声中。
这是选项卡:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <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包含以下形式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <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论坛中也问过这个问题。
这是
- http://code.google.com/p/primefaces/issues/detail?id=3423。
- http://code.google.com/p/primefaces/issues/detail?id=4143
如您所见,第一个标记为WontFix。第二个是重复项,但最后您将看到另一个解决方法。
如果您仔细阅读该线程,可能会注意到某些解决方法仍然存在。如果您被迫使用
如果我正确理解了您的问题,实际上有一个非常简单的解决方法,可以防止重复显示消息。
将您的咆哮声更改为以下内容:
1 | <p:growl id="growl" globalOnly="true" autoUpdate="true" showDetail="true" /> |
如果要从备用bean端添加消息,可以使用以下代码进行操作:
1 2 | FacesContext.getCurrentInstance() .addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"title","details"); |
如果您想完全安全,甚至可以指定咆哮的for属性,并将其作为