[英]How to show a popup in primefaces with the requiredMessages, only if these messages exist?
I want to show a popup with the requiredMessages of some inputText fields when I click on a submit button. 我想在单击提交按钮时显示一些带有一些inputText字段的requiredMessages的弹出窗口。 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.
我已经在oncomplete标签上尝试使用bean变量和javascript,但我无法使其正常工作。 If I put visible="true" in p:dialog, the popup is always displayed, although I try to control it from the commandButton.
如果我在p:对话框中输入visible =“true”,则会始终显示弹出窗口,但我尝试从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.
提前致谢。
Standard JSF and PrimeFaces does not support request based EL evaluation in on*
attributes. 标准JSF和PrimeFaces不支持
on*
属性中基于请求的EL评估。 RichFaces is the only who supports that. RichFaces是唯一支持它的人。 Besides, the standard JSF
<h:commandButton>
does not have an oncomplete
attribute at all. 此外,标准JSF
<h:commandButton>
根本没有oncomplete
属性。 You're probably confusing with PrimeFaces <p:commandButton>
你可能会对PrimeFaces
<p:commandButton>
感到困惑
There are several ways to achieve this: 有几种方法可以实现这一目标:
Check the condition in the visible
attribute of the <p:dialog>
instead. 请改为检查
<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}">
Use PrimeFaces <p:commandButton>
instead, the PrimeFaces JS API supports the #{facesContext.validationFailed}
condition through the args
object as well: 使用PrimeFaces
<p:commandButton>
代替,PrimeFaces JS API也通过args
对象支持#{facesContext.validationFailed}
条件:
<p:commandButton ... oncomplete="if (args.validationFailed) dlg1.show()" />
If you need to check for what kind of messages, here is a way that I made work with primefaces. 如果您需要检查哪种消息,这是我使用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.
由于在更新后调用了primefaces oncomplete,通过更新包含javascript函数的组件,可以在执行之前使用最新的#facesContext.maximumSeverity}值重建javascript函数。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.