2012-12-23 50 views
3

我對p:tabView組件存在嚴重問題。我已將dynamic="true"cache="false"設置爲tabView。其中一個選項卡的某些輸入組件設置爲required="true"Primefaces tabView在選項卡更改上執行表單驗證

現在,當我每次更改選項卡時,表單驗證正在發生,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> 

我無法找到我在做什麼錯誤,以及如何解決它。 我使用PrimeFrame 3.4.2與JSF Mojarra 2.1.7-jbossorg。任何指針都會對我非常有幫助。

我在PrimeFaces論壇也提過這個問題。

回答

4

這就是tabView的工作原理。下面是從PrimeFaces跟蹤的相關問題:

正如你所看到的第一個被標記爲WontFix。 第二個是重複的,但最後你會看到另一個解決方法

如果您仔細閱讀該線程,則可能會注意到某些解決方法仍存在。如果您被迫使用tabView,請嘗試使用其中之一。如果您想在不同的選項卡中使用輸入,請考慮使用PrimeFaces - Wizard

+0

我不知何故有錯誤理解這個問題的感覺,但我不確定。是的,這是記錄的行爲,'tabView'會驗證輸入(根據JSF規範),但至少從PF 4.0開始,有'immediate =「true」'跳過驗證階段。另請參閱下面的答案 – Vogel612

0

如果我正確理解您的問題,實際上有一個相當簡單的解決方法來防止重複顯示的消息。

你的咆哮更改爲以下:

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

如果你想從支持豆方添加的消息,你可以做到這一點與下面的代碼:

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

如果你想是完全安全的,您甚至可以爲咆哮指定一個for屬性,並將其作爲addMessage的第一個參數。

相關問題