0 Replies Latest reply on Jul 11, 2012 3:57 AM by jmansop

    Retrieving a bean from popupPanel

    jmansop

      Hi everybody.

       

      The main idea of my work is to edit users. To do this I call an action from my xhtml and perform a user info loading into a popupPanel. This working properly. The problem comes when I need to edit those fields and call the action to apply the changes. The bean which I'm retrieving is the original one, without the changes.

       

      Here you can see my code.

       

       

      1) Table with the users. Las column to perform actions (modify)

      <div class="manage-section-row">
           <h:panelGrid columnClasses="ut">
                <rich:dataScroller for="usersTable" maxPages="5" />
                     <rich:dataTable value="#{listOfUsersBean.users}" var="user" id="usersTable" rows="20">
      
                          <!-- Data Columns -->
                          <rich:column>
                               <f:facet name="header">
                                    <h:outputText value="User Name" />
                               </f:facet>
                               <h:outputText value="#{user.username}" />
                          </rich:column>
      
                          ...
                          More columns to show different fields
                          ...
      
                          <!-- Column to perform actions against the users -->
                          <rich:column>
                               <f:facet name="header">
                                    <h:outputText value="Actions" />
                               </f:facet>
      
                          <!-- Command link to open the user modification panel and load the data -->
                               <a4j:commandLink id="modifyUserLink" oncomplete="#{rich:component('modify_user_popup')}.show(); return false;" actionListener="#{myActions.loadUser}" render="userModificationPopupPanel" >
                                    <h:graphicImage value="modify_user.png" style="border:0" />
                                    <f:param name="idxUser" value="#{listOfUsersBean.users.indexOf(user)}" />
                                    <rich:tooltip for="modifyUserLink" value="Mofify User" />
                               </a4j:commandLink>
                          </rich:column>
                     </rich:dataTable>
                <rich:dataScroller for="usersTable" maxPages="5" />
           </h:panelGrid>
      </div>
      
      

       

      2) LoadUser action

      public void loadUser(ActionEvent e) {
           FacesContext context = FacesContext.getCurrentInstance(); 
           ListOfUsersBean usersBean = (ListOfusersBean) context.getELContext().getELResolver().getValue(context.getELContext(), null, "listOfUsersBean");
      
           // Uses the parameter from xhtml to detect the desired user
           String idxUser = context.getExternalContext().getRequestParameterMap().get("idxUser");
      
           if (StringUtils.checkNotNullAndNotEmpty(idxUser)) {
                Integer userIndex = Integer.parseInt(idxUser);
      
                // Retrieves the desired user from the list
                MyUser userBean = usersBean.getUsers().get(userIndex);
      
                // Adds the user to the context
                context.getELContext().getELResolver().setValue(context.getELContext(), null, "userToModifyBean", userBean);
            }
      }
      

       

      3) popupPanel

      <a4j:outputPanel id="userModificationPopupPanel">
           <div class="manage-section-row">
      
      
                <!-- Panel to modify the selected user -->
                <rich:popupPanel id="modify_user_popup" modal="false" autosized="true" resizeable="false" >
                     <f:facet name="header">
                          <h:outputText value="Simple popup panel" />
                     </f:facet>
                     <f:facet name="controls">
                          <h:outputLink value="#" onclick="#{rich:component('modify_user_popup')}.hide(); return false;">
                               X
                          </h:outputLink>
                     </f:facet>
      
                     <!-- Button to create the user -->
                     <div class="manage-section-row">
                          <div class="button-modify">
                                <a4j:commandButton styleClass="green" oncomplete="#{rich:component('modify_user_popup')}.hide(); return false;" actionListener="#{myActions.modifyUser}" render="userModificationOutputPanel" value="Apply Changes" />
                          </div>
                     </div>
      
                     <!-- Fields to be modified -->
                     <div class="manage-section-row">
                          <div class="label">
                               <h:outputText escape="false" value="User Name" />
                          </div>
                          <div class="content">
                               <h:inputText value="#{userToModifyBean.username}"></h:inputText>
                          </div>
                     </div>
      
                     ...
                     More fileds to be modified
                     ...     
      
                </rich:popupPanel>
           </div>
      </a4j:outputPanel>
      

       

      4) ModifyUser action (here is were the error is happening)

      public void modifyUser(ActionEvent e) {
           FacesContext context = FacesContext.getCurrentInstance();
      
           // This is the bean which is comming with the original user info instead of the info that was modified in the popupPanel
           GenericUser userBean = (GenericUser) context.getELContext().getELResolver().getValue(context.getELContext(), null, "userToModifyBean");
           UserService userService = (UserService) context.getELContext().getELResolver().getValue(context.getELContext(), null, "userService");
      
           userBean = userService.updateUser(userBean);
           setActualView(context);
      }
      

       

       

      Using RichFaces 4.2.2 Final