2 Replies Latest reply on Apr 24, 2012 6:31 AM by afuentes

    rich:popupPanel new Bean created when a4j:commandButton

    afuentes

      I am having some problems with rich:popupPanel, it is like a new Bean (view scope) was created when i pressed button inside the popup.

       

      I am not sure if it is a RichFaces bug or it is a bug from my code, since in another code I have wrote it seems to be correct, and that code is nearly the same. Now, I'm completely lost.

       

      Well, the platform is RF4.2, JSF 2.0.8, JDK 1.6.0.30 with eclipse and Windows 7.

       

      The web application uses extendedDataTable to list the roles, with some operations (Edit, Delete), when the edit is clicked, a popup with the record data and buttons (apply, exit) are shown. When you click the popupPanel buttons, the first time doesn't work, and when click it again, a new object Bean is created and the actionListener is executed.

       

      The page...

                     <h:form id="formDataTableFilterID">

                          <rich:panel id="panelID" header="listado">

                              <a4j:commandButton value="refresh" render="tableID" style="visibility: hidden" /><br/>

                                                     

                              <rich:extendedDataTable id="tableID" value="#{roleManager.roleList}" var="row">

                                  <f:facet name="noData">

                                         <h:outputText value="#{general.nodata}" />

                                     </f:facet>

                                    

                                     <f:facet name="header">

                                         <h:outputText value="elementsNumber: " />

                                         <h:outputText value="#{fn:length(roleManager.roleMap)}" />

                                     </f:facet>

                                    

                                     <f:facet name="footer">

                                      <h:outputText value="elementsNumber: " />

                                         <h:outputText value="#{fn:length(roleManager.roleMap)}" />

                                  </f:facet>

                                    

                                     <rich:column >

                                      <f:facet name="header">

                                          <h:outputText value="Id" /><br/>

                                      </f:facet>

                                      <h:outputText value="#{row.id}" >

                                      </h:outputText>

                                  </rich:column>

                                 

                                  <rich:column filterExpression="#{fn:containsIgnoreCase(row.name, roleManager.currentNameFilterValue)}">

                                      <f:facet name="header">

                                          <h:outputText value="nombre" /><br/>

                                          <h:inputText value="#{roleManager.currentNameFilterValue}">

                                              <a4j:ajax event="change" render="tableID" execute="@this"/>

                                          </h:inputText>

                                      </f:facet>

                                      <h:outputText value="#{row.name}" />

                                  </rich:column>

                                 

                                  <rich:column styleClass="rf_column_centered" width="80px">

                                      <f:facet name="header">

                                          <h:outputText value="Operations" /><br/>

                                          <a4j:commandLink id="newUserID" render="inputID" actionListener="#{roleManager.newRoleListener()}" execute="@this" oncomplete="#{rich:component('popupPanelID')}.show()">

                                              <h:outputText value="New"/>

                                          </a4j:commandLink>

                                          <rich:tooltip target="newUserID">

                                                <strong><h:outputText value="New"/></strong>

                                          </rich:tooltip>

                                      </f:facet>

                                     

                                      <a4j:commandLink id="editUserID" render="popupPanelID" actionListener="#{roleManager.editRoleListener(row.id)}" execute="@this" oncomplete="#{rich:component('popupPanelID')}.show()">

                                          <h:outputText value="Edit"/>

                                      </a4j:commandLink>

                                      <h:outputText value=" - "/>

                                      <a4j:commandLink id="removeUserID" render="panelID" actionListener="#{roleManager.removeRoleListener(row.id)}" execute="@this" onclick="if(!confirm('deleteConfirmation')){return false;}">

                                          <h:outputText value="Cancel"/>

                                      </a4j:commandLink>

                                  </rich:column>

                                 </rich:extendedDataTable>

                          </rich:panel>

                      </h:form>

                      <rich:popupPanel id="popupPanelID" header="PopUp" autosized="true" modal="true">

                          <h:form id="formID" >

                              <rich:panel id="inputID">

                                     

                                      <h:outputText value="Id: "/>

                                      <h:inputText value="#{roleManager.roleSelected.id}" />

                                      <br/>

                                      <h:outputText value="nombre "/>

                                      <h:inputText value="#{roleManager.roleSelected.name}" />

                                      <br/>

                                      <a4j:commandButton value="#" style="visibility: hidden" ></a4j:commandButton>

                                     

                                      <a4j:commandButton value="Apply"

                                              execute="inputID"

                                              actionListener="#{roleManager.applyListener}" />

                                     

                                      <h:commandButton value="Apply 2">

                                          <a4j:ajax event="click" render="panelID"

                                              listener="#{roleManager.applyListener}"  execute="@this" />

                                      </h:commandButton>

                                     

                                      <h:commandButton value="Exit">

                                          <a4j:ajax event="click"

                                              render="panelID" execute="@this"

                                              oncomplete="#{rich:component('popupPanelID')}.hide()"/>

                                      </h:commandButton>

                              </rich:panel>

                          </h:form>

                      </rich:popupPanel>

       

       

      The Bean...

      public class RoleManagerBean

      {

          private String currentNameFilterValue = new String();

          private Role roleSelected = new Role(0,"empty");

          private Map<Integer, Role> roleMap = new HashMap<Integer, Role>();

          /**

           *

           */

          private static final long serialVersionUID = 1L;

       

          /**

           * @return the roleSelected

           */

          public Role getRoleSelected()

          {

              System.out.println(" - getRoleSelected!!");

              System.out.println(" --> this: " + this);

              System.out.println(" --> roleSelected: " + roleSelected);

              return roleSelected;

          }

       

          /**

           * @param roleSelected the roleSelected to set

           */

          public void setRoleSelected(Role roleSelected)

          {

              System.out.println(" - setRoleSelected!!");

              System.out.println(" --> this: " + this);

              System.out.println(" --> roleSelected: " + roleSelected);

              this.roleSelected = roleSelected;

          }

       

          /**

           * @return the currentNameFilterValue

           */

          public String getCurrentNameFilterValue()

          {

              return currentNameFilterValue;

          }

       

          /**

           * @param currentNameFilterValue the currentNameFilterValue to set

           */

          public void setCurrentNameFilterValue(String currentNameFilterValue)

          {

              this.currentNameFilterValue = currentNameFilterValue;

          }

       

          public Map<Integer, Role> getRoleMap()

          {

              System.out.println(" - roleList!!");

              if(roleMap.size()==0)

              {

                  System.out.println(" ---------------------------------------------------> this: " + this);

                  roleMap = new HashMap<Integer, Role>();

             

                  roleMap.put(1, new Role(1,"ROLE_USER"));

                  roleMap.put(2, new Role(2,"ROLE_ADMIN"));

                  roleMap.put(3, new Role(3,"ROLE_BIDOC"));

                  roleMap.put(4, new Role(4,"ROLE_IT"));

                  roleMap.put(5, new Role(5,"ROLE_SUPER"));

                  roleMap.put(6, new Role(6,"ROLE_DIR"));

              }

              return(roleMap);

          }

         

          public List<Role> getRoleList()

          {

              List<Role> roleList = new LinkedList<Role>();

              roleList.addAll(getRoleMap().values());

              return(roleList);

          }

         

          public void processAccessDropListener(DropEvent event)

          {

              System.out.println(" - processAccessDrop!!");

          }

       

          public void processAdminDropListener(DropEvent event)

          {

              System.out.println(" - processAdminDrop!!");

          }

         

          public void saveListener(ActionEvent event)

          {

              System.out.println(" - saveListener!!");

          }

         

          public void applyListener(ActionEvent event)

          {

              System.out.println(" - applyListener(event)!!");

              System.out.println(" ---------------------------------------------------> this: " + this);

              System.out.println(" --> roleSelected: " + roleSelected);

              if(roleSelected!=null)

                  roleMap.put(roleSelected.getId(), roleSelected);

              else

                  System.out.println(" --> roleSelected: null");

          }

         

          public void applyListener()

          {

              System.out.println(" - applyListener()!!");

              System.out.println(" ---------------------------------------------------> this: " + this);

              System.out.println(" --> roleSelected: " + roleSelected);

              roleMap.put(roleSelected.getId(), roleSelected);

          }

         

          public void newRoleListener(ActionEvent event)

          {

              System.out.println(" - newRoleListener!!");

              System.out.println(" --> this: " + this);

              System.out.println(" --> roleSelected: " + roleSelected);

          }

         

          public void editRoleListener(int roleId)

          {

              System.out.println(" - editRoleListener!!");

              System.out.println(" --> this: " + this);

              System.out.println(" --> roleSelected: " + roleSelected);

              roleSelected = roleMap.get(roleId);

          }

         

          public void removeRoleListener(int roleId)

          {

              System.out.println(" - removeRoleListener!!");

              System.out.println(" --> this: " + this);

              System.out.println(" --> roleSelected: " + roleSelected);

              roleMap.remove(roleId);

          }  

       

      The log I get

       

      - roleList!!

      ---------------------------------------------------> this: demo.RoleManagerBean@1ac6bf80

      - roleList!!

      - roleList!!

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@1ac6bf80

      --> roleSelected: Role [id=0, name=empty]

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@1ac6bf80

      --> roleSelected: Role [id=0, name=empty]

      ----------------------------------------------------------before edit button click - roleList!!

      - editRoleListener!!

      --> this: demo.RoleManagerBean@1ac6bf80

      --> roleSelected: Role [id=0, name=empty]

      - roleList!!

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@1ac6bf80

      --> roleSelected: Role [id=1, name=ROLE_USER]

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@1ac6bf80

      --> roleSelected: Role [id=1, name=ROLE_USER]

      -----------------------------------------------------------popup is shown, before apply button click (first click)

      -----------------------------------------------------------before apply button clicked again(second click)

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@48cb14ba

      --> roleSelected: Role [id=0, name=empty]

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@48cb14ba

      --> roleSelected: Role [id=0, name=empty]

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@48cb14ba

      --> roleSelected: Role [id=0, name=empty]

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@48cb14ba

      --> roleSelected: Role [id=0, name=empty]

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@48cb14ba

      --> roleSelected: Role [id=0, name=empty]

      - getRoleSelected!!

      --> this: demo.RoleManagerBean@48cb14ba

      --> roleSelected: Role [id=1, name=empty]

      - applyListener(event)!!

      ---------------------------------------------------> this: demo.RoleManagerBean@48cb14ba

      --> roleSelected: Role [id=1, name=ROLE_USER]

      -------------------------------------------------------------------before exit button click

      - roleList!!

      - roleList!!

      - roleList!!

      --------------------------------------------------------------------popup is hidden


       

      Any help will be apreciated!!!

      /Alberto

        • 1. Re: rich:popupPanel new Bean created when a4j:commandButton
          jamesc1

          I ran into this problem.

           

          This is what I did to resolve the problem.

           

          Put the popupPanel inside your first form.

          Remove the form element from inside the popupPanel

          Add domElementAttachment="parent" attribute to the popupPanel.

           

          <h:form id="formDataTableFilterID">

               // Your other stuff before...

               <rich:popupPanel id="popupPanelID" header="PopUp" autosized="true" modal="true" domElementAttachment="parent">

                         // no form here now

                    </rich:popupPanel>

            </h:form>

          • 2. Re: rich:popupPanel new Bean created when a4j:commandButton
            afuentes

            Thanks James,

            I have just tested that your solution is right!!

             

            It seems the bean is not recreated.

             

            Thanks again!