8 Replies Latest reply on Aug 8, 2006 8:57 AM by hdslkf hklsdg

    DataModel sincronization issue...

    Ângelo Luis Newbie

      I have 2 variables thats points to 1 Set... One from a Entity from a OneToMany relashionship e another from my SFSB whit @DataModel anotation, just beacuse i cant have @DataModel from a Entity (the data model selection dont work's)...

      @DataModelSelection(value="rolesFromRoleGroup")
      private Role role;
      
      @DataModel
      private Set<Role> rolesFromRoleGroup;
      
      @Factory("rolesFromRoleGroup")
      public void listRolesFromRoleGroup(){
       if(this.roleGroup!=null)
       rolesFromRoleGroup = roleGroup.getRoles();
      }


      but in a action i add one role to this Set from the roleGroup.getRoles() variable... the first time the t:dataTable show the role, but the second and if i remove the first role from this Set the t:tableTable dont updates, is always showing the same value...

      I see in teh forum that the updates is derteminate from the isDirty method, and my equals method from Role entity is ok...



        • 1. Re: DataModel sincronization issue...
          hdslkf hklsdg Apprentice

          I guess that you maybe do not update rolesFromRoleGroup explicitely, so it always keeps its initial state. One way to it right is to add a e.g. @Observer("rolesFromRoleGroupChange") to the listRolesFromRoleGroup() method, and to fire Events.instance().raiseEvents("rolesFromRoleGroupChange") every time you delete, add or update a role entity.

          • 2. Re: DataModel sincronization issue...
            Ângelo Luis Newbie

            i try that, but i get a javax.ejb.EJBException: Application Error: no concurrent calls on stateful beans

            • 3. Re: DataModel sincronization issue...
              hdslkf hklsdg Apprentice

              Please show the whole code of your beans.

              • 4. Re: DataModel sincronization issue...
                Ângelo Luis Newbie

                 

                public class SystemRoleGroupManagerBean implements SystemRoleGroupManager, Serializable{
                
                 @PersistenceContext(type=PersistenceContextType.EXTENDED)
                 private EntityManager entityManager;
                
                 ......
                
                 // inject by Seam
                
                 @In(required=false)
                 @Out(required=false)
                 private RoleGroup roleGroup;
                
                 @DataModelSelection(value="rolesFromRoleGroup")
                 private Role role;
                
                 // data models
                
                 @DataModel
                 private Set<Role> rolesFromRoleGroup;
                
                 @SelectItems(labelMethod="getNome")
                 private List<Role> roless; // lista de permissões
                
                 // factory methods
                
                 @Factory("rolesFromRoleGroup")
                 @Observer("rolesFromRoleGroupChange")
                 public void listRolesFromRoleGroup(){
                 if(this.roleGroup!=null){
                 rolesFromRoleGroup = roleGroup.getRoles();
                 }
                 }
                
                 @Factory("roless")
                 public void listRoles() {
                 roless = entityManager.createQuery("from Role order by :nome").setParameter("nome", "nome").getResultList();
                 }
                
                 // metodos de negocio
                
                 @End
                 public void addRoleGroup() {
                 if(roleGroup.getId()!=null)
                 updateUsuariosWithRoleGroup(roleGroup);
                 roleGroup = entityManager.merge(roleGroup); // save or updates
                 }
                
                 /**
                 * Sincronizar os papeis dos usuarios com o grupo.
                 * @param roleGroup grupo de permissões
                 */
                 private void updateUsuariosWithRoleGroup(RoleGroup roleGroup){
                 }
                
                 @Begin(join=true)
                 public void addRoleToRoleGroup() {
                 // o index é o index da listagem.
                 // TODO para @Selectable ou @SelectItemsSelection quando implementarem essa solução.
                 Role _role = roless.get(index);
                 roleGroup.addRole(_role);
                 Events.instance().raiseEvent("rolesFromRoleGroupChange");
                 }
                
                 @Begin(join=true)
                 public void removeRoleFromRoleGroup() {
                 roleGroup.removeRole(role);
                 Events.instance().raiseEvent("rolesFromRoleGroupChange");
                 }
                
                 // destroy method
                
                 @Remove @Destroy
                 public void destroy(){}
                }


                • 5. Re: DataModel sincronization issue...
                  hdslkf hklsdg Apprentice

                  Your code looks good. The only problem source - as far as I can imagine - could be if roleGroup is null (for any reason). Maybe you should try setting a breakpoint in the listRolesFromRoleGroup() method to see if it's called correctly. If this ain't possible (I have problems with debugging to since I can't create a new launch configuration under Eclipse WTP 3.2) I would do it like that:

                  
                   @Factory("rolesFromRoleGroup")
                   @Observer("rolesFromRoleGroupChange")
                   public void listRolesFromRoleGroup(){
                   System.out.println("Entered listRolesFromRoleGroup, roleGroup = " + roleGroup);
                   if(this.roleGroup!=null){
                   System.out.println("rolesFromRoleGroup OLD = " + rolesFromRoleGroup);
                   rolesFromRoleGroup = roleGroup.getRoles();
                   System.out.println("rolesFromRoleGroup NEW = " + rolesFromRoleGroup);
                   }
                   }
                  


                  Then you only need a look at the log to see if this part of your code really works like it should.

                  • 6. Re: DataModel sincronization issue...
                    Ângelo Luis Newbie

                    Yes, this code enters... and the rolesFromRoleGroup references the same Set of roleGroup.roles, but if a add or remove some item from this Set the t:datatable dont show, its just show the first modification (when the references is set) and if the Set is with 1000 elements , he doesn't care, only show the first modification...

                    • 7. Re: DataModel sincronization issue...
                      Ângelo Luis Newbie

                       

                      "angelogalvao" wrote:
                      Yes, this code enters... and the rolesFromRoleGroup references the same Set of roleGroup.roles, but if a add or remove some item from this Set the t:datatable dont show, its just show the first modification (when the references is set) and if the Set is with 1000 elements , he doesn't care, only show the first modification...


                      Ops, this code enters just the first time...

                      • 8. Re: DataModel sincronization issue...
                        hdslkf hklsdg Apprentice

                        So that was the problem? :)