1

How can I set up a Primefaces Dialog to not hide, when there are "required-messages" open? At this moment, the dialog will closing by clicking on the "Speichern" Button, and when reopened, the messages appears... I would like to let the dialog open, when there are unfilled required fields:

<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>
4

2 回答 2

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;

}

感谢您的帮助!

于 2013-04-26T07:41:31.383 回答
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(); "
于 2013-04-25T10:41:48.160 回答