仅在这些消息存在的情况下,如何在带有要求的消息的素面中显示弹出窗口? [英] How to show a popup in primefaces with the requiredMessages, only if these messages exist?
问题描述
当我单击提交按钮时,我想显示一个带有某些inputText字段的requiredMessages的弹出窗口.但是仅在有这些消息的情况下.我尝试在oncomplete标记上使用bean变量和javascript,但无法使其正常运行.如果我在p:dialog中放置visible ="true",则始终显示弹出窗口,尽管我尝试通过commandButton对其进行控制.现在,我有了这个,但是从不显示弹出窗口:
I want to show a popup with the requiredMessages of some inputText fields when I click on a submit button. But just only in case of there are those messages. I have tried with bean variable and javascript on the oncomplete tag, but I'm not able to make it work properly. If I put visible="true" in p:dialog, the popup is always displayed, although I try to control it from the commandButton. Now, I have this, but the popup is never displayed:
<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>
我该怎么做?预先感谢.
How can I do this? Thanks in advance.
推荐答案
标准JSF和PrimeFaces在on*
属性中不支持基于请求的EL评估. RichFaces是唯一支持该功能的人.此外,标准JSF <h:commandButton>
根本没有oncomplete
属性.您可能对PrimeFaces <p:commandButton>
Standard JSF and PrimeFaces does not support request based EL evaluation in on*
attributes. RichFaces is the only who supports that. Besides, the standard JSF <h:commandButton>
does not have an oncomplete
attribute at all. You're probably confusing with PrimeFaces <p:commandButton>
有几种方法可以做到这一点:
There are several ways to achieve this:
-
请改为在
<p:dialog>
的visible
属性中检查条件.
<p:dialog visible="#{not empty facesContext.messageList}">
或者如果您只想显示验证消息而不是所有消息
or if you want to show validation messages only instead of all messages
<p:dialog visible="#{facesContext.validationFailed}">
使用PrimeFaces <p:commandButton>
代替,PrimeFaces JS API也通过args
对象支持#{facesContext.validationFailed}
条件:
Use PrimeFaces <p:commandButton>
instead, the PrimeFaces JS API supports the #{facesContext.validationFailed}
condition through the args
object as well:
<p:commandButton ... oncomplete="if (args.validationFailed) dlg1.show()" />
这篇关于仅在这些消息存在的情况下,如何在带有要求的消息的素面中显示弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!