3 Replies Latest reply on Jul 21, 2010 10:05 AM by Doug Costa

    ModalPanel Hide Issue

    Doug Costa Newbie

      In my application I have users clicking on a button to add a new entry into our database.  This button displays a rich:modalPanel which contains some fields.  When they click a button "add" my backing bean does some validation of the entered data.  If I find something wrong I want to show an error message on the modal Panel.

      here is my code:

       

      {code}<rich:modalPanel id="panel">

      <f:facet name="controls">
              <h:panelGroup>
                  <h:outputLabel value="X"   id="hidelink"/>
                  <r:componentControl  id="hidelinkControl" for="panel" attachTo="hidelink" operation="hide"  event="onclick" />
              </h:panelGroup>
          </f:facet>

           <h:form>
                <div id="message" align="center"><h:messages id="entryError" errorClass="errorMessage"  /></div>

                <!--- some feilds -->

               <h:commandButton value=" ADD " action="#{controller.add}">
                     <a:support event="onClick" reRender="entryError" />
                </h:commandButton>

           </h:form>

      </rich:modalPanel>{code}

      in my backing bean:

      {code}private HtmlModalPanel panel;

      ...

      public void add() {

           if (entred values not valid) {

                addErrorMessage("All coverage fields required to add a coverage.");

           }

      }

      private void addErrorMessage(String msg) {

           FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);

           FacesContext fc = FacesContext.getCurrentInstance();

           fc.addMessage(panel.getClientId(fc), facesMsg);

      }

      ...{code}

      The problem with this is that when add is clicked the modalPanel is hidden.  If I click on the button to show the modalPanel again i will see it with the error message displayed.  Is there some way to keep the modalPanel from hiding when I rerender a specific part (the h:messages)?

        • 1. Re: ModalPanel Error Messages causing hide
          Doug Costa Newbie

          Actually, I am also having the same problem with a table I added to the modalPanel.

          The panel's code is now:

           

          {code}<rich:modalPanel id="panel">
               <f:facet name="controls">

                  <h:panelGroup>

                      <h:outputLabel value="X"   id="hidelink"/>

                      <r:componentControl  id="hidelinkControl" for="panel" attachTo="hidelink" operation="hide"  event="onclick" />

                  </h:panelGroup>

              </f:facet>
               <h:form>

                    <div id="message" align="center"><h:messages id="entryError" errorClass="errorMessage"  /></div>
                    <!--- some feilds -->
                   <h:commandButton value=" ADD " action="#{controller.add}">

                         <a:support event="onClick" reRender="entryError, table" />

                    </h:commandButton>

                    <r:scrollableDataTable id="table" >

                    <!--columns -->

                    </r:scrollableDataTable>
               </h:form>
          </rich:modalPanel>

          {code}


          When I click the add button, a row is to be added to the table in the backing bean.  A row is added but the panel closes after the button is clicked.

          • 2. Re: ModalPanel Error Messages causing hide
            Nick Belaevski Master

            Hi Doug,

             

            Try removing a4j:support and replacing h:commandLink with a4j:commandLink.

            • 3. Re: ModalPanel Error Messages causing hide
              Doug Costa Newbie

              Thanks, that solved the problem.