如果打开“required-messages”,如何设置Primefaces对话框不隐藏?此时,对话框将通过单击“Speichern”按钮关闭,当重新打开时,会显示消息...当有未填写的必填字段时,我想打开对话框:
<h:panelGrid id="createNewPat" columns="3" cellpadding="1" style="margin:0 auto;">
<h:outputText for="versNr" value="Versicherten-Nr.:" />
<p:inputMask id="versNr" value="#{patientenBean.versNr}" required="true"/>
<p:message for="versNr" />
<p:commandButton id="saveBtn" value="Speichern"
action="#{patientenBean.createPatient}"
oncomplete="if (!args.messageOccured) createNewPat.hide();"
update="patForm" />
<p:commandButton id="resetBtn" value="Reset" type="reset" />
</h:panelGrid>
答案 0 :(得分:3)
昨天解决了问题(经过3小时的谷歌搜索和测试),就像这样:
<p:dialog header="Patient erfassen" widgetVar="createNewPat"
resizable="true" id="createPatDlg" >
<h:form id="dlgErf">
<h:panelGrid id="createNewPat" columns="3" cellpadding="1"
style="margin:0 auto;">
<h:outputText for="versNr" value="Versicherten-Nr.:" />
<p:inputMask id="versNr" value="#{patientenBean.versNr}"
required="true" >
<!-- <f:validateLength minimum="2" /> -->
</p:inputMask>
<p:message for="versNr" />
以下是按钮:
<p:commandButton id="saveBtn" value="Speichern"
action="#{patientenBean.createPatient}"
oncomplete="if (!args.validationFailed){createNewPat.hide()}"
update="createNewPat"/>
<p:commandButton id="resetBtn" value="Reset" process="@this" update="createNewPat"
action="#{patientenBean.reset}">
<p:resetInput target="createNewPat" />
</p:commandButton>
</h:panelGrid>
现在重置按钮也可以工作 - Bean中的方法只是用于将所有属性设置为NULL:
public void reset() {
logger.info("Reset-Methode: Leeren der Felder!");
versNr=null;
name=null;
vorname=null;
strasseNr=null;
plz=null;
ort=null;
geschlecht=null;
geburtsdatum=null;
versNrEdit=null;
nameEdit=null;
vornameEdit=null;
strasseNrEdit=null;
plzEdit=null;
ortEdit=null;
geschlechtEdit=null;
geburtsdatumEdit=null;
}
Thanx的帮助!
答案 1 :(得分:1)
如果您希望对话框不关闭,则commandButton
(或更新对话框容器的任何组件)必须在对话框内更新。不要更新对话框的容器,例如:
<p:dialog id="dlg">
<p:panel id="pntest">
// content here
<p:commandButton update=":#{p:component('pntest')}"/>
</p:panel>
</p:dialog>
如果没有,则必须在oncomplete
:
oncomplete="(args.messageOccured)? createNewPat.show(): createNewPat.hide(); "