5 Replies Latest reply on Oct 12, 2007 2:37 PM by pmuir

    EntityHome and EntityQuery difference/problem

    dnikolov

      Note that this topic isn't about the difference between EntityHome and EntityQuery in general, but about the different behavior I get when I put a certain bit of functionality in classes extending these two.

      So, my setup:

      I followed ch 1 of the seam tutorial and put in a @DataModel and a @DataModelSelection on a data table so I can detect which row is selected.

      I set up the table so that if the current row is selected inputText elements are shown so a user can edit the information in the row. Otherwise outputText elements are rendered.

      On each row I also have an edit commandLink that is wired to a method that does something like this:

      public String edit() {
       this.deselectAll();
       if(!this.selectionItem.getSelected()) {
       this.selectionItem.setSelected(true);
       }
       return null;
      }
      


      I also have a save button on each row that does something like:
      public String save() {
       EntityObj obj = this.selectionItem.getEntityObj();
       EntityManager em = this.getEntityManager();
       em.persist(obj);
       return null;
      }
      


      This seems to work fine in a class extending EntityHome (provided that in the save function I set the current instance to obj and then do persist on the current instance), but it doesn't work in the class extending entity query.

      Tracing through this shows that after the user edits the input boxes and the save function is called, the EntityObj gotten from this.selectionItem.getEntityObj() has the values that were there before the user edit.

      selectionItem is the @DataItemSelection of course.

      So.. any ideas why this works in one class and not in another? I am using the pages generated by seamgen to test this: I use a ___Edit.xhtml page with the ___Home.java, and a ___List.xhtml with the ___List.java.

      Any feedback is greatly appreciated.

        • 1. Re: EntityHome and EntityQuery difference/problem
          matt.drees

          Did you manually set the scopes on your subclasses? If not, then they are inherited from their superclasses. EntityHome's default scope is Conversation, while EntityQuery's default scope is Event. This affects where @DataModel stores the DataModel, if you didn't specify its scope attribute.

          • 2. Re: EntityHome and EntityQuery difference/problem
            dnikolov

            Good call. I'd tried this before without success, I think because I hadn't correctly started the conversation. Setting the scope to conversation seems to do the trick. Thanks!

            This opens another problem however: The header sorting doesn't work as desired in Conversation scope as the table isn't immediately sorted. I'll have to think about how to fix that. If you have encountered this or have suggestions let me know.

            • 3. Re: EntityHome and EntityQuery difference/problem
              dnikolov

              Update: Setting the scope to CONVERSATION makes those edit and save links work (provided they are h:commandLink's and not s:link's), but then the header sorting of the table doesn't work.

              With the scope set to PAGE the sorting works and the entity that's being edited with the edit and save operations gets updated but doing em.persist on it doesn't write the information into the database.

              Any ideas why that is and how it can be remedied?

              • 4. Re: EntityHome and EntityQuery difference/problem
                dnikolov

                Also, I tried only setting the scope on the data model, but this also didn't seem to have an effect. I've seen the scope descriptions in the Seam tutorial, but since I am new to Java EE in general, I might need to do a bit more reading. Any suggestions for good online tutorials or books?

                • 5. Re: EntityHome and EntityQuery difference/problem
                  pmuir

                  You should use EntityHome inside a long running conversation and EntityQuery should be in the event scope. You should use page parameters not datamodel/datamodelselection.

                  You could try Michael Yuan's books on Seam.