2011-04-29 51 views
1

當單擊按鈕但對話框應該顯示爲不隱藏時,我需要在對話框中顯示的JSF驗證消息。JSF驗證當按鈕單擊時,對話框中的消息顯示

<h:form prependId="false"> 
    <h:panelGrid columns="1" cellpadding="5"> 
     <p:commandButton value="Modal" onclick="dlg2.show();" type="button" /> 
    </h:panelGrid> 

<p:dialog header="Modal Dialog" widgetVar="dlg2" modal="true" height="200" width="400"> 
    <h:panelGrid columns="1" > 
    <p:messages /> 
    <p:inputText id="txt" value="#{converterBean.doubleValue}" required="true"/> 
    <p:commandButton ajax="false" value="Submit" action="#{converterBean.submit}" /> 
    </h:panelGrid> 
</p:dialog> 



    </h:form> 

回答

3

你的情況很相似this example from the primefaces showcase

請注意,<h:form><p:dialog>裏面。還請注意示例的LoginBean.java回調參數的設置方式。

變化,它更新您的<p:messages>(它在示例更新<p:growl><p:commandButton>

1

那麼,有在這個過程被稱爲一個選擇,你只能處理某些領域 例如下面顯示的內容將只提交數據僅在某些ID下,而不是整個形式

 <p:dialog id="dialog" header="Login" widgetVar="dlg" width="600" > 

      <h:panelGrid columns="3" cellpadding="5" id="someID"> 
       <h:outputLabel for="username" value="Username: *" /> 
       <p:inputText 
        id="username" required="true" label="username" requiredMessage="Field required" /> 
       <p:message for="username"/> 

       <h:outputLabel for="password" value="Password: * " /> 
       <h:inputSecret 
        id="password" required="true" label="password" requiredMessage="Field required" /> 
       <p:message for="password"/> 

       <f:facet name="footer"> 
        <p:commandButton value="Login" update="display" process="someID" onsuccess="dlg.hide()" onerror="dlg.show()" /> 
       </f:facet> 
      </h:panelGrid> 
     </p:dialog> 
相關問題