【问题标题】:JSF validation Message Display in Dialog Box when Button click单击按钮时在对话框中显示 JSF 验证消息
【发布时间】:2011-04-29 11:22:55
【问题描述】:

单击按钮时,我需要在对话框中显示 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>

【问题讨论】:

    标签: jsf


    【解决方案1】:

    您的情况与this example from the primefaces showcase非常相似。

    请注意&lt;h:form&gt;&lt;p:dialog&gt; 里面。还要注意示例的 LoginBean.java 中回调参数是如何设置的。

    更改&lt;p:commandButton&gt;,它会更新您的&lt;p:messages&gt;(在示例中它会更新&lt;p:growl&gt;

    【讨论】:

      【解决方案2】:

      好吧,在被调用的过程中有一个选项,您只能处理某些字段 例如,下面显示的内容只会提交 someID 下的数据,而不是整个表单

              <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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-30
        • 1970-01-01
        • 1970-01-01
        • 2020-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多