6 Replies Latest reply on Jun 8, 2007 2:09 PM by gavin.king

    @DataModel modifications

    georgesberscheid

      Hi,

      I have a @DataModel (HashSet myEntries) in a SESSION-scoped JAVABEAN Seam component with a @Factory method that retrieves initial data from the database and I display it in myList.xhtml.
      I also have an action method addEntry() that does em.persist(newEntry) and myEntries.add(newEntry) and returns to myList.xhtml.

      The entry has been added to the database table and to the myEntries Set, but when I return to myList.xhtml I can't see it. Is the initial myEntries Set (as returned from the @Factory method) cached somewhere?

      If I touch WEB-INF/web.xml of my .war directory (which causes re-deployment) the new entry shows up in myList.xhtml.

      This is Seam 1.2.0patch1 on AS 4.2.0CR1.
      Any ideas what I'm doing wrong here?

      Thanks,
      Georges

        • 1. Re: @DataModel modifications

          I don't know if this is a best-practice or not, but what I'm doing is in my display page, say foo.xhtml, I have foo.page.xml that has an action tag that executes a refresh() method in the component managing my list.

          In this refresh() method I forcibly call the factory method to reload the list.

          Like I said--not sure if this is the best/preferred way to do it, but it seems to work well. If anyone knows of a more graceful way of getting around any caching I'd be interested to know as well.

          Greg

          • 2. Re: @DataModel modifications

             


            I have a @DataModel (HashSet myEntries) in a SESSION-scoped JAVABEAN Seam component. (...) Is the initial myEntries Set (as returned from the @Factory method) cached somewhere?


            Yes. It is session scoped so it is "cached" in the session.

            You could simply add the entity to your set after it has been persisted/merged. This will save you a trip to the database.

            Regards

            Felix

            • 3. Re: @DataModel modifications
              georgesberscheid

              Ok, a few more details. The entity itself is not a Seam component, so it doesn't have a Seam context. The Java Bean I'm talking about is a SESSION scoped Seam component that simply holds the Set of entities.

              I did add the entity to the Set, but my DataTable doesn't display it. Also, refreshing it from the database would be a little overkill, since it's already in the Set. When does the DataTable read the contents of the Set annotated with @DataModel?

              • 4. Re: @DataModel modifications

                If you change the collection on which the @Datamodel is based you have to reoutject the @Datamodel. Either annotate you action component accordingly or use a scope such that the life span of the @Datamodel will fit your needs, e.g. eject it into the conversation and end the conversation on deleting the entities.

                Regards

                Felix


                • 5. Re: @DataModel modifications
                  rhinosystemsinc

                  Georges,
                  I am having almost the same problem. My scenario is different, but the DataModel is being cached... and if I change the datamodel to stateless or the SFSB to SLSB, it complains w/ exceptions.
                  How did you solve your problem?
                  Can you give me code samples?
                  Thanks!

                  • 6. Re: @DataModel modifications
                    gavin.king

                     

                    "georgesberscheid" wrote:
                    Ok, a few more details. The entity itself is not a Seam component, so it doesn't have a Seam context. The Java Bean I'm talking about is a SESSION scoped Seam component that simply holds the Set of entities.

                    I did add the entity to the Set, but my DataTable doesn't display it. Also, refreshing it from the database would be a little overkill, since it's already in the Set. When does the DataTable read the contents of the Set annotated with @DataModel?


                    This might be a bug that I just fixed in CVS.

                    Try with this new implementation of SetDataModel:

                    http://fisheye.jboss.com/browse/~raw,r=1.4/JBoss/jboss-seam/src/main/org/jboss/seam/jsf/SetDataModel.java