5 Replies Latest reply on Apr 12, 2011 3:11 PM by snecek

    Save data from pickList to bean

    snecek

      Hello,


      I'm trying to save form data to the bean. But after sending the form data is saved in the bean and the bean is recreated.


      Where is my problem?



      Form:



      <h:form>
              <rich:pickList
                      id="pickListId"
                      value="#{coreRoleActionBean.rolesActions}">
                        <s:selectItems value="#{coreRoleActionBean.rolesActionsList}" var="actions" label="#{actions.name}"/>
                        <s:convertEntity />
              </rich:pickList>
              <s:button action="#{coreRoleActionBean.save()}" value="Save"></s:button>
      </h:form>








      Bean:




      @Stateful
      @Name("coreRoleActionBean")
      @Scope(ScopeType.SESSION) 
      public class CoreRoleActionPicklistBean implements CoreRoleActionPicklist {
              
              @In    
              EntityManager entityManager;
              
              private List<CoreRoleAction> rolesActions = new ArrayList<CoreRoleAction>();
              
              private List<CoreRoleAction> rolesActionsList = new ArrayList<CoreRoleAction>();
              
              @In(required=false)
              private CoreRole currentRole;
              
              @Create
              public void init(){
                      System.err.println("Wooow3");
                      rolesActions = currentRole.getActions();
                      rolesActionsList = entityManager.createNamedQuery("RoleAction.findAll").getResultList();
              }
              
              public void save() {
                      System.err.println("Saving data ! ");
                      System.err.println(rolesActions);
                      System.err.println(rolesActionsList);
                      currentRole.setActions(rolesActionsList);
                      entityManager.merge(currentRole);
                      entityManager.flush();
              }
              
              @Destroy @Remove
              public void destroy() {
                      
              }
              
              
              
              public List<CoreRoleAction> getRolesActions() {
                      return rolesActions;
              }
      
              public void setRolesActions(List<CoreRoleAction> rolesActions) {
                      this.rolesActions = rolesActions;
              }
      
              public List<CoreRoleAction> getRolesActionsList() {
                      return rolesActionsList;
              }
      
              public void setRolesActionsList(List<CoreRoleAction> rolesActionsList) {
                      this.rolesActionsList = rolesActionsList;
              }
      }





      Thanx for your help.

        • 1. Re: Save data from pickList to bean
          lvdberg

          Hi,


          do you mean a new instance of the bean is created and its INIT-method is called, without any error-messages whatsoever?


          Leo

          • 2. Re: Save data from pickList to bean
            snecek

            Hi Leo,


            exactly as you wrote. No error, everything is initialized, but after clicking Save output method save():




            Saving your data!
            RolesActions unchanged - the same as the initialization, the changes were not applied in pickList




            It will be a mistake on my part, but I don't see it: (


            • 3. Re: Save data from pickList to bean
              lvdberg

              Hi,



              Some things which come to mind:





              • How is the currentRole outjected ?

              • Has the relation between Role and Action a Lazy fetch ?

              • Is the cascading from Role to Action not present ?

              • Is it a Many to many, so is there an need to add the other side also ?

              • Where comes the second log from ? (I can't see it in your code)





              Leo



              • 4. Re: Save data from pickList to bean
                lvdberg

                Hi,


                just after clicking the submit button I reread you code....


                You use a Seam-button. Change it to whatever other button. The S.-one doesn't submit form data !!


                Leo

                • 5. Re: Save data from pickList to bean
                  snecek

                  Hi Leo,


                  You guy really:) Everything is ok.


                  Have a nice evening.


                  Thanks a lot.


                  Filip