7 Replies Latest reply on Feb 19, 2007 4:36 PM by Pete Muir

    Factory and injection in EntityHome

    jk;l jkl; Expert

      I have an EntityHome that contains the following code. When I go to page to create the entity, the myEntity factory variable is already populated with the first entity in the dataModel list, even though nothing has been selected (and myEntityHome.managed evaluates to true, even though it shouldn't, because nothing from the list has been selected). Why might this be?

      @Name("myEntityHome")
      public class MyEntityHome extends EntityHome<MyEntity> {
      
       @Factory
       public MyEntity getMyEntity() { return getInstance(); }
      
       @In("#{myQuery.dataModel.rowData}")
       public void setInstance(MyEntity instance) {
       super.setInstance(instance);
       }
      
      }


      In the create page, I have the following. The first time I access the page, myEntity.name is populated with the value of the first row of "myQuery.dataModel", even though "myQuery.dataModel.rowData" should be empty because no row has yet been selected. How do I fix this so that it behaves correctly and shows nothing, because nothing has been selected? This should work, right?

      <h:form>
       <h:inputText value="#{myEntity.name}" />
       <h:commandButton value="Create" action="#{myEntityHome.persist}" />
      </h:form>


        • 1. Re: Factory and injection in EntityHome
          jk;l jkl; Expert

          My guess of what's happening here is that when I first access the myEntity factory to return the instance, "myQuery.dataModel.rowData" automatically selects the first entity in the dataModel.

          This isn't the correct behavior right? Isn't a dataModel only supposed to be populated when the a row is actually selected, or does it always have a default selected value upon access?

          I have no idea how to proceed from this...

          • 2. Re: Factory and injection in EntityHome
            Saeed Iqbal Novice

            was that stuff generated from seam-gen? because i've not seen that code in my entityhome. whats going on?

            why do you have @In for the row data in there? isnt that supposed to be set in the serializable class? atleast thats how my seam-gen made it. dont know how to proceed anyway :P

            • 3. Re: Factory and injection in EntityHome
              jk;l jkl; Expert

              Stepping through my debugger, the problem seems to be that ListDataModel's setRowIndex(int) is being called with a value of 0 upon first access... is there something I can do in my EntityHome to prevent this from happening, or is it a "bug"? (Meaning why is setRowIndex being called when nothing has been selected?) Anyways, once I've sorted it out I think it'll work.

              saeediqbal1, this is not seam-gen. I'm trying a slightly different but valid way of deleting entities from a list. I don't have anything special in my serializable class, if by that you mean entity (you can't inject into entities, using @In)

              • 4. Re: Factory and injection in EntityHome
                Saeed Iqbal Novice

                hey how are you using debugger with jboss AS ? are you using the wtp version of eclipse? feel free to email me saeedcs ...at... gmail dot com

                thanks!
                -saeed

                • 5. Re: Factory and injection in EntityHome
                  Luis Daniel Rangel Tovar Newbie

                  ... try removing that weird @In{row.something} ... if that's not enough, try starting a new conversation. By the way, i had trouble using inheritance, using declarative approach fixed some errors, I believe that's a bug.

                  • 6. Re: Factory and injection in EntityHome
                    jk;l jkl; Expert

                    Well that "weird" @In is the whole reason behind this topic.

                    I really don't want to have to use page parameters for certain things, like removing an entity from a list of entities, because then I'd have to build in all sorts of unnecessary logic that I wouldn't have to worry about by doing it this way.

                    But I still have no idea why this isn't working...could one of the Seam developers perhaps address this issue?

                    • 7. Re: Factory and injection in EntityHome
                      Pete Muir Master

                      Build a very very simple example (that *just* shows this) created using seam-gen from current CVS, remove the lib dir, and email it to me (pmuir at bleepbleep dot org dot uk)