2

当我单击提交按钮时,我想显示一个带有一些 inputText 字段的 requiredMessages 的弹出窗口。但仅在有这些消息的情况下。我已经尝试在 oncomplete 标记上使用 bean 变量和 javascript,但我无法使其正常工作。如果我在 p:dialog 中放入 visible="true",则始终显示弹出窗口,尽管我尝试从 commandButton 控制它。现在,我有了这个,但从未显示弹出窗口:

<h:inputText id="Scheme" 
            required="true"
            requiredMessage="Required.">
</h:inputText>

<h:commandButton id="submitModify" value="#{msg['systemdetail.modify']}"
             action="#{sistem.modify}"
             oncomplete="if (#{facesContext.maximumSeverity != null}) {dlg1.show();}">
</h:commandButton>

<p:dialog id="popup"
          style="text-align:center"
          widgetVar="dlg1"
          modal="true">  
    <h:messages layout="table"/>
</p:dialog> 

我怎样才能做到这一点?提前致谢。

4

2 回答 2

12

标准 JSF 和 PrimeFaces 不支持on*属性中基于请求的 EL 评估。RichFaces 是唯一支持这一点的人。此外,标准的 JSF<h:commandButton>根本没有oncomplete属性。您可能对 PrimeFaces 感到困惑<p:commandButton>

有几种方法可以实现这一点:

  • 检查相反的visible属性中的条件<p:dialog>

    <p:dialog visible="#{not empty facesContext.messageList}">
    

    或者如果您只想显示验证消息而不是所有消息

    <p:dialog visible="#{facesContext.validationFailed}">
    

  • 改用 PrimeFaces <p:commandButton>,PrimeFaces JS API也通过对象支持#{facesContext.validationFailed}条件:args

    <p:commandButton ... oncomplete="if (args.validationFailed) dlg1.show()" />
    
于 2012-05-29T14:33:13.240 回答
2

If you need to check for what kind of messages, here is a way that I made work with primefaces. Since primefaces oncomplete is called after update, by updating the component holding the javascript function, the javascript function can be rebuilt using the latest #facesContext.maximumSeverity} values before executed.

<p:commandButton
    oncomplete="executeAfterUpdate()"
    update="updatedBeforeOnComplete"/>

<h:panelGroup id="updatedBeforeOnComplete">
    <script language="JavaScript" type="text/javascript">
        //
        function executeAfterUpdate(){
            if (#{facesContext.maximumSeverity==null
               or facesContext.maximumSeverity.ordinal=='1'})
            {
                // your code to execute here
                someDialog.show();
            }
        }
        //
    </script>
</h:panelGroup>
于 2012-10-12T17:14:55.617 回答