5 Replies Latest reply on Sep 30, 2010 6:40 AM by Andrey Markhel

    rendered problems in the form

    Martial Maillot Newbie

      Hello,

       

      In first, sorry for my bad english.

       

      I create a new Seam project. I generate the entities from the database with 2 table (users and groups). In a user, we can found a list of group.

       

      Entity Users  :

       

       

      Session userSelected

       

       

      package com.adecco.esb.supervision.session.main; import java.io.Serializable; import javax.persistence.EntityManager; import javax.persistence.Query; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.faces.FacesMessages; import com.adecco.esb.supervision.entity.Users; @Name("usersSelectedHelper") @Scope(ScopeType.CONVERSATION) public class UsersSelectedHelper implements Serializable {     private static final long serialVersionUID = 1L;     @In(create = true)     EntityManager entityManager;     @In(required = true)     Users loggedUser;     @In     FacesMessages facesMessages;     private Users selectedUsers;     private boolean editUsers;     private boolean addUsers;     /**      * @return the selectedUsers      */     public Users getSelectedUsers() {         if (selectedUsers == null) {             selectedUsers = new Users();         }         return selectedUsers;     }     public void setSelectedusersId(long id) {         String queryString;         queryString = "SELECT u FROM Users u WHERE u.idusers=:iduser";         // Creating the query         Query query = entityManager.createQuery(queryString).setParameter(                 "iduser", id);         // Getting the contacts list         selectedUsers = (Users) query.getSingleResult();     }     /**      * @param selectedUsers      *            the selectedUsers to set      */     public void setSelectedUsers(Users selectedUsers) {         this.selectedUsers = selectedUsers;     }     /**      * @return the editUsers      */     public boolean isEditUsers() {         return editUsers;     }     /**      * @param editUsers      *            the editUsers to set      */     public void setEditUsers(boolean editUsers) {         this.editUsers = editUsers;     }     public void createNewEmptyUserInstance() {         setSelectedUsers(new Users());     }     public void insertNewUser() {         entityManager.persist(getSelectedUsers());         entityManager.flush();         // De-selecting the current contact         setSelectedUsers(null);         setEditUsers(false);     }     public void saveContactData() {         entityManager.merge(getSelectedUsers());         entityManager.flush();         // De-selecting the current contact         setSelectedUsers(null);         setEditUsers(false);     }     public void deleteSelectedContact() {         entityManager.remove(getSelectedUsers());         entityManager.flush();         // De-selecting the current contact         setSelectedUsers(null);         setEditUsers(false);     }     public boolean isSelectedUserManaged() {         return getSelectedUsers() != null                 && entityManager.contains(getSelectedUsers());     }     /**      * @return the addUsers      */     public boolean isAddUsers() {         return addUsers;     }     /**      * @param addUsers      *            the addUsers to set      */     public void setAddUsers(boolean addUsers) {         this.addUsers = addUsers;     } }

       

      to finish the xhtml

       

       

      In edit.xhtml and add.xhtml, we have a simple form

       

       

      My problem is very simple :

      If i set the rendered property

       

       

      When the form appear (click on edit link in the table), all input are correctly feed (blank for add and pre fed for edit). When i click on the button to save the user, nothing happens... it's the same for the edit form.

      If i remove the property rendered, the two forms always appear in the page but if i click on the add button or edit button, the user are add and the table is refresh.

       

      What the problem in the first case (rendered property set) ?

       

      Thanks

        • 1. Re: rendered problems in the form
          Martial Maillot Newbie

          Oups  ENtity :

           

           
          @Entity
          @Table(name = "USERS", schema = "TIBCOFUNC")
          public class Users implements java.io.Serializable {
          
              private static final long serialVersionUID = 1L;
              private long idusers;
              private Gender gender;
              private String login;
              private String firstname;
              private String lastname;
              private String details;
              private Set preferenceses = new HashSet(0);
              private List groups = new ArrayList(0);
              private Set instanceses = new HashSet(0);
          
              public Users() {
              }
          
              public Users(long idusers, String login, String firstname) {
                  this.idusers = idusers;
                  this.login = login;
                  this.firstname = firstname;
              }
          ...
          }
          
          • 2. Re: rendered problems in the form
            Martial Maillot Newbie

            Session :

             
            package com.adecco.esb.supervision.session.main;
            
            import java.io.Serializable;
            
            import javax.persistence.EntityManager;
            import javax.persistence.Query;
            
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.faces.FacesMessages;
            
            import com.adecco.esb.supervision.entity.Users;
            
            @Name("usersSelectedHelper")
            @Scope(ScopeType.CONVERSATION)
            public class UsersSelectedHelper implements Serializable {
            
                 private static final long serialVersionUID = 1L;
            
                 @In(create = true)
                 EntityManager entityManager;
            
                 @In(required = true)
                 Users loggedUser;
            
                 @In
                 FacesMessages facesMessages;
            
                 private Users selectedUsers;
            
                 private boolean editUsers;
            
                 private boolean addUsers;
            
                 /**
                  * @return the selectedUsers
                  */
                 public Users getSelectedUsers() {
                      if (selectedUsers == null) {
                           selectedUsers = new Users();
                      }
                      return selectedUsers;
                 }
            
                 public void setSelectedusersId(long id) {
                      String queryString;
                      queryString = "SELECT u FROM Users u WHERE u.idusers=:iduser";
            
                      // Creating the query
                      Query query = entityManager.createQuery(queryString).setParameter(
                                "iduser", id);
            
                      // Getting the contacts list
                      selectedUsers = (Users) query.getSingleResult();
                 }
            
                 /**
                  * @param selectedUsers
                  *            the selectedUsers to set
                  */
                 public void setSelectedUsers(Users selectedUsers) {
                      this.selectedUsers = selectedUsers;
                 }
            
                 /**
                  * @return the editUsers
                  */
                 public boolean isEditUsers() {
                      return editUsers;
                 }
            
                 /**
                  * @param editUsers
                  *            the editUsers to set
                  */
                 public void setEditUsers(boolean editUsers) {
                      this.editUsers = editUsers;
                 }
            
                 public void createNewEmptyUserInstance() {
                      setSelectedUsers(new Users());
                 }
            
                 public void insertNewUser() {
                      entityManager.persist(getSelectedUsers());
                      entityManager.flush();
            
                      // De-selecting the current contact
                      setSelectedUsers(null);
                      setEditUsers(false);
                 }
            
                 public void saveContactData() {
                      entityManager.merge(getSelectedUsers());
                      entityManager.flush();
            
                      // De-selecting the current contact
                      setSelectedUsers(null);
                      setEditUsers(false);
                 }
            
                 public void deleteSelectedContact() {
                      entityManager.remove(getSelectedUsers());
                      entityManager.flush();
            
                      // De-selecting the current contact
                      setSelectedUsers(null);
                      setEditUsers(false);
                 }
            
                 public boolean isSelectedUserManaged() {
                      return getSelectedUsers() != null
                                && entityManager.contains(getSelectedUsers());
                 }
            
                 /**
                  * @return the addUsers
                  */
                 public boolean isAddUsers() {
                      return addUsers;
                 }
            
                 /**
                  * @param addUsers
                  *            the addUsers to set
                  */
                 public void setAddUsers(boolean addUsers) {
                      this.addUsers = addUsers;
                 }
            
            }
            
            

            xhtml :

             

             

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="https://ajax4jsf.dev.java.net/ajax">
                
                <a4j:form id="fUsers">
                    <rich:dataTable id="tUserList" cellpadding="0" cellspacing="0" width="75%"
                        border="0" var="user" align="center" value="#{usersListHelper.usersList}">
                        <f:facet name="header">
                            <rich:columnGroup>
                                <rich:column>
                                    <h:outputText value="#{applicationRessources.user}" />
                                </rich:column>
                                <rich:column>
                                    <h:outputText value="#{applicationRessources.description}" />
                                </rich:column>
                            </rich:columnGroup>
                        </f:facet>
                        
                        <rich:column style="text-align: center; width:35%;" 
                            filterBy="#{user.lastname}" sortBy="#{user.lastname}">
                            <h:outputText value="#{user.firstname} #{user.lastname}" />
                        </rich:column>
                        <rich:column style="text-align: center;">
                            <h:outputText value="#{user.details}" />
                        </rich:column>
                        <rich:column style="text-align: center;">
                            <a4j:commandLink value="Edit" reRender="panEdit, panAdd">
                                <f:setPropertyActionListener value="#{user}" target="#{usersSelectedHelper.selectedUsers}" />
                                <f:setPropertyActionListener value="#{true}" target="#{usersSelectedHelper.editUsers}" />
                                <f:setPropertyActionListener value="#{false}" target="#{usersSelectedHelper.addUsers}" />
                            </a4j:commandLink>
                        </rich:column>
            
                    </rich:dataTable>
                    
                    <a4j:commandButton reRender="panAdd, panEdit"
                        oncomplete="Richfaces.showModalPanel('pEditUser');" 
                        value="#{applicationRessources.add_user}"
                        action="#{usersSelectedHelper.createNewEmptyUserInstance}">
                        <f:setPropertyActionListener value="#{true}" target="#{usersSelectedHelper.addUsers}"/>
                        <f:setPropertyActionListener value="#{false}" target="#{usersSelectedHelper.editUsers}"/>
                    </a4j:commandButton>
                </a4j:form>
                
                <a4j:outputPanel id="panAdd">
                    <a4j:outputPanel rendered="#{usersSelectedHelper.addUsers}">
                        <ui:include src="/admin/users/add.xhtml" />
                    </a4j:outputPanel>
                </a4j:outputPanel>
                
                <a4j:outputPanel id="panEdit">
                    <a4j:outputPanel rendered="#{usersSelectedHelper.editUsers}">
                        <ui:include src="/admin/users/edit.xhtml" />
                    </a4j:outputPanel>
                </a4j:outputPanel>
            
            </ui:composition>
            

             

            form (add.xhtml) :

             

            <a4j:form id="fAddUser">
                    <a4j:outputPanel id="panEditUser">
                        <h:panelGrid columns="2" styleClass="left" witdh="45%">
                            <h:outputLabel for="userTitle">
                                    #{applicationRessources.user_title} :
                            </h:outputLabel>
                            <h:selectOneListbox value="#{usersSelectedHelper.selectedUsers.gender}" size="1">
                                <s:selectItems var="gender" value="#{genderList.resultList}" label="#{gender.gender}" 
                                    noSelectionLabel="Please select..." />
                                <s:convertEntity />
                            </h:selectOneListbox>
                            <h:outputLabel for="userFirstname">
                                    #{applicationRessources.user_firstname} :
                            </h:outputLabel>
                            <h:inputText id="userFirstname" value="#{usersSelectedHelper.selectedUsers.firstname}"
                                style="width: 200px;">
                            </h:inputText>
                            <h:outputLabel for="userLastname">
                                    #{applicationRessources.user_lastname} :
                            </h:outputLabel>
                            <h:inputText id="userLastname" value="#{usersSelectedHelper.selectedUsers.lastname}"
                                style="width: 200px;">
                            </h:inputText>
                            <h:outputLabel for="userLogin">
                                    #{applicationRessources.user_login} :
                            </h:outputLabel>
                            <h:inputText id="userLogin" value="#{usersSelectedHelper.selectedUsers.login}"
                                style="width: 200px;">
                            </h:inputText>
                            <h:outputLabel for="userDetails">
                                    Description : 
                            </h:outputLabel>
                            <h:inputText id="userDetails" value="#{usersSelectedHelper.selectedUsers.details}"
                                style="width: 200px;">
                            </h:inputText>
                        </h:panelGrid>
                        <h:panelGrid columns="2" styleClass="right" witdh="45%">
                            <h:outputLabel for="userTitle">
                                    #{applicationRessources.user_admin} :
                            </h:outputLabel>
                        </h:panelGrid>
                        <rich:pickList value="#{usersSelectedHelper.selectedUsers.groups}">
                            <s:selectItems var="group" value="#{groupsList.resultList}" label="#{group.name}"/>
                            <s:convertEntity />
                        </rich:pickList>
                        
                        <a4j:commandButton id="btn_confirm_add" action="#{usersSelectedHelper.insertNewUser}" 
                            value="#{applicationRessources.confirm}" reRender="tUserList, fEditUser" />
                        
                    </a4j:outputPanel>
                </a4j:form>
            
            • 3. Re: rendered problems in the form
              Andrey Markhel Newbie

              Try replace next code from your main xhtml:

              <a4j:outputPanel id="panAdd">
                      <a4j:outputPanel rendered="#{usersSelectedHelper.addUsers}">
                          <ui:include src="/admin/users/add.xhtml" />
                      </a4j:outputPanel>
                  </a4j:outputPanel>
                 
                  <a4j:outputPanel id="panEdit">
                      <a4j:outputPanel rendered="#{usersSelectedHelper.editUsers}">
                          <ui:include src="/admin/users/edit.xhtml" />
                      </a4j:outputPanel>
                  </a4j:outputPanel>

              to

               

              <h:panelGroup id="panAdd" rendered="#{usersSelectedHelper.addUsers}">
                          <ui:include src="/admin/users/add.xhtml" />
              </
              h:panelGroup>
                
              <
              h:panelGroup id="panEdit" rendered="#{usersSelectedHelper.editUsers}">
                    <ui:include src="/admin/users/edit.xhtml" />
              </
              h:panelGroup>
              • 4. Re: rendered problems in the form
                Martial Maillot Newbie

                Doesn't work. When i click on add bouton or edit link, nothing happens. The h:panelGroup is no rendered when the page is loading. When i click on the button, the reRender="panAdd" doesn't find the h:panelGroup with the id panAdd.

                • 5. Re: rendered problems in the form
                  Andrey Markhel Newbie

                  Maybe this help you, replace your 2 panels with one:

                   

                  <h:panelGroup id="pan">
                              <ui:include src="
                  #{usersSelectedHelper.getPage}" />
                  </
                  h:panelGroup>

                  And method

                  public String getPage(){

                       if(addUsers){

                            return "/admin/users/add.xhtml";

                       }

                       if(editUsers){

                            return "/admin/users/edit.xhtml";

                       }

                  }

                  And always reRender "pan", I think it is simpler and should work.