3 Replies Latest reply on Feb 1, 2009 2:44 AM by Ali Gohar

    Seam not applying values to entity

    Ali Gohar Newbie

      Hi


      I am having some real strange issues any help will be appreciated. Here is the scenario:


      On first page i have a s:link i start conversation here using propagation begin. Then on next page i show list of all Users. User is an entity class with name as user. Here the list is shown using datatable and i use @Model and @Factory annotations to display list of users. It is working fine. This action is stateful.


      Then when someone clicks on any user, I outject a User object. Here is some excerpt from my action class. I am not listing all the code to shorten the post as much as possible


      @Stateful
      @Name("usersListAction")
      @Restrict("#{s:hasRole('Admin')}")
      public class UsersListAction implements UserListLocal {
      @PersistenceContext(type=PersistenceContextType.EXTENDED)
              private EntityManager entityManager;
              
              @DataModel
              private List<User> userList;
              
              @DataModelSelection
              private User modelUser;
              
              @Out(required=false, value="selectedUser")
              private User mUser;
      



      Here is the method which gets invoked when the link is clicked


             @Begin(join=true)
              public void selectUser() {
                      this.mUser = modelUser;
              }
      



      This mUser object is outjected and i am displaying details of selected user on next page so that administrator can edit the details. Here is the code from next class:


      @Stateful
      @Name("userDetailAction")
      @Restrict("#{s:hasRole('Admin')}")
      public class UserDetailAction implements UserDetailLocal {
      
              @In(required=false, value="selectedUser")
              private User selectedUser;
      
              @PersistenceContext(type=PersistenceContextType.EXTENDED)
              private EntityManager em;
      



      Here comes the problem. It displays the values perfectly fine on my xhtml and i've bound the values of h:inputText fields with selectedUser.firstName etc. Now when i use h:commandButton and call editUser action. It doesn't work. The action is not called at all. Here is the action method in UserDetailAction class above:


              @End
              public void editUser() {
                      em.merge(selectedUser);
              }
      



      But when i use s:button the action is called perfectly alright but this time the values are not applied to the bean, it is still loading old values and em.merge does nothing. I have turned the show sql property ON but i can't see any update statement only select ones. May be it is due to the fact that seam is not applying values to entity so entity is not changed and update is not called. I am really stuck with this one. Please help, it is pissing me off. I have tried everything even defined attributes in UserDetailAction with firstName, lastName etc and then set them into entity but still em.merge does nothing. I have tried to make my beans stateless but still no success.


      Thanks

        • 1. Re: Seam not applying values to entity
          Ali Gohar Newbie

          Any ideas please???? I am really stuck. I am using seam 2.1.0 SP1 with Jboss 4.2.3.GA if that helps?


          cheers

          • 2. Re: Seam not applying values to entity
            alberto Gori Novice

            I think you should solve the h:commandButton issue before spending time on s:button. The standard button simply should work.
            My first suggestion is to put a


            <h:messages/>
            



            on the page. This component could give you usefull information about not calling action issue.


            My second suggestion is that you don't need any merge operation. Simply flush the entity manager.
            You should disable flush on commit behavior, changing it to manual flushing, and call


            em.flush();
            



            on action ending conversation.
            For implementation details give a look at Seam documentation.



            Another suggestion: I could be wrong, but what about using only


            @Out @DataModelSelection selectedUser;
            


            instead of two properties?

            • 3. Re: Seam not applying values to entity
              Ali Gohar Newbie

              thanks for the reply. I've tried all this but no success. I've already placed h:messages but it doesn't display an message apart from the success message i've displayed. I've tried to use



              @Out @DataModelSelection User selectedUser



              But this doesn't work. It doesn't outject the value.


              Then I changed the flush mode to MANUAL but still no success.


              Its really weird i can't figure out whats going wrong. Any other ideas??


              Thanks again.