[英]How to show a popup in primefaces with the requiredMessages, only if these messages exist?
我想在单击提交按钮时显示一些带有一些inputText字段的requiredMessages的弹出窗口。 但只是在有这些消息的情况下。 我已经在oncomplete标签上尝试使用bean变量和javascript,但我无法使其正常工作。 如果我在p:对话框中输入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>
我怎样才能做到这一点? 提前致谢。
标准JSF和PrimeFaces不支持on*
属性中基于请求的EL评估。 RichFaces是唯一支持它的人。 此外,标准JSF <h:commandButton>
根本没有oncomplete
属性。 你可能会对PrimeFaces <p:commandButton>
感到困惑
有几种方法可以实现这一目标:
请改为检查<p:dialog>
的visible
属性中的条件。
<p:dialog visible="#{not empty facesContext.messageList}">
或者如果您只想显示验证消息而不是所有消息
<p:dialog visible="#{facesContext.validationFailed}">
使用PrimeFaces <p:commandButton>
代替,PrimeFaces JS API也通过args
对象支持#{facesContext.validationFailed}
条件:
<p:commandButton ... oncomplete="if (args.validationFailed) dlg1.show()" />
如果您需要检查哪种消息,这是我使用primefaces的方法。 由于在更新后调用了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.