2015-09-08 54 views
0

我有一個窗體,其中有一個按鈕,用於打開Rich:modalPanel,其中另一個窗體和底部的兩個按鈕; CloseSave關閉Rich:modalPanel保存正確

  • Close:執行onclick="#{rich:component('mp')}.hide()並隱藏模式面板。
  • Save:驗證表單的字段顯示錯誤,如果不完整,如果表單正確,則保存在數據庫中。重置表單但不關閉Rich:modalPanel

我想關閉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 /> 

但是,這些代碼總是關閉(或隱藏)模式面板,不僅如果保存完成。只有在保存好的情況下才能關閉這個模式面板的另一種方法是什麼?

錯誤彈出是:

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

回答

0

解決:

只需加入另一個​​與表示驗證在彈出消息的條件。

// 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}" /> 
0

您可以使用的onComplete屬性a4j:commandButton,像

<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');}"