[英]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.