正确保存后关闭Rich:modalPanel

Close Rich:modalPanel after save correctly

我有一个带有按钮的表单,可以打开一个 Rich:modalPanel,里面有另一个表单,底部有两个按钮; CloseSave

我想关闭 Rich:modalPanel 仅当表单正常并保存时,但我做不到。我试过:

插入Javascript:

<a4j:commandButton value="${msg.guardar}" styleClass="boton" reRender="personaForm" action="#{persona.guardarAuxiliar}" onclick="#{rich:component('mp')}.hide()"/><br />

<a4j:commandButton value="${msg.guardar}" styleClass="boton" reRender="personaForm" action="#{persona.guardarAuxiliar}" oncomplete="#{rich:component('mp')}.hide()"/><br />

仅使用 RichFaces:

<a4j:commandButton value="${msg.guardar}" styleClass="boton" reRender="personaForm" action="#{persona.guardarAuxiliar}">
    <rich:componentControl for="mp" operation="hide" event="onclick" />
</a4j:commandButton><br />

<a4j:commandButton value="${msg.guardar}" styleClass="boton" reRender="personaForm" action="#{persona.guardarAuxiliar}">
    <rich:componentControl for="mp" operation="hide" event="oncomplete" />
</a4j:commandButton><br />

但是这段代码总是关闭(或隐藏)模态面板,不仅仅是在保存完成时。是不是另一种方法只有在保存正常的情况下才能关闭这个modalPanel?

错误弹出窗口是:

<a4j:outputPanel ajaxRendered="true">
    <h:messages id="error" styleClass="error"></h:messages>
</a4j:outputPanel> 

 <rich:modalPanel id="panel2" width="350" height="100" zindex="4000" showWhenRendered="${persona.hayErrores || persona.exito}">
    <f:facet name="header">
        <h:panelGroup>
            <h:outputText value="${msg.error}" rendered="#{persona.hayErrores}"></h:outputText>
            <h:outputText value="${msg.info}" rendered="#{persona.exito}"></h:outputText>
        </h:panelGroup>
    </f:facet>
    <f:facet name="controls">
        <h:panelGroup>
            <h:graphicImage value="/estilos/general/img/iconos/close.png" style="cursor:pointer" id="hidelink2"/>
            <rich:componentControl for="panel2" attachTo="hidelink2" operation="hide" event="onclick"/>
        </h:panelGroup>
    </f:facet>
     <a4j:outputPanel ajaxRendered="true">
        <h:outputText value="#{persona.listaErrores}" rendered="#{persona.hayErrores}" styleClass="error"/>
        <h:outputText value="#{msg.personaExito}" rendered="#{persona.exito}"/>
      </a4j:outputPanel>
</rich:modalPanel>

已解决:

只需在显示验证的弹出消息中添加另一个 rich:componentControl 条件。

// If its wrong, only closes this popup
<rich:componentControl for="panel2" attachTo="hidelink2" operation="hide" event="onclick" rendered="#{persona.hayErrores}" />
// If its ok, closes this popup and 'mp' modalPanel
<rich:componentControl for="panel2,mp" attachTo="hidelink2" operation="hide" event="onclick" rendered="#{persona.exito}" />

您可以使用 a4j:commandButtononcomplete 属性,例如

<a4j:commandButton action="#{persona.guardarAuxiliar}"
                    oncomplete="Richfaces.hideModalPanel('mp')"
                    value="#{msg.guardar}" reRender="personaForm" />

或有条件

oncomplete="if (#{!yourAction.hasErrors}) Richfaces.hideModalPanel('mp')"

检查验证错误的经典案例

oncomplete="if (#{facesContext.maximumSeverity == null}) {Richfaces.hideModalPanel('mp');}"