2011-04-29 82 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> 
相关问题