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

    Save data from pickList to bean

    Filip Senk Newbie

      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.