0 Replies Latest reply on Jul 17, 2011 1:04 AM by Tom Bryan

    Scope problem with EntityQuery, DataModel, and calling action methods called from a dataTable

    Tom Bryan Newbie

      I need some help with Seam 2.2 best practices or design patterns.


      I can't seem to get the row's entity passed to an commandLink's action method.  It seems like this should be a really common use case, but I'm confused about how the various components should be scoped.  I couldn't find an appropriate example in the Seam distribution or in Dan Allen's open18 sample project. 


      Here's what we're doing.


      At first, my search pages ran in a long running conversation, but I noticed that I had a lot of abandoned conversations lying around from when the user navigated away from the search page.  I decided to make our search pages operate without a long-running conversation.  For pagination of search results, we use an approach like this one: http://www.andygibson.net/blog/tutorial/codeless-ajax-ordered-and-paginated-tables-in-seam/


      Making search pages use no server-side state works well because ad hoc searches don't have a well-defined end point for ending a long running conversation or cleaning up a session.  Conversations are not started until the user is actually participating in a directed use case, such as creating a new entity.  Navigation menu items do not propagate the conversation so that the state from one use case does not pollute a new use case when the user navigates away without completing or canceling. 


      All of this works really cleanly, and I was very happy with Seam until I discovered that h:commandLinks or s:links in the dataTable aren't getting the correct selection.  Using either @DataModelSelection or action="#{aComponent.method(_rowVariable)}" doesn't appear to work unless the @DataModel for the dataTable still exists at the time of the postback. 


      Since we handle pagination via RichFaces and AJAX, I thought that I could use the Page scope for the EntityQuery that supplies the @DataModel since that would permit me to keep the DataModel available without the side effect of a bunch of abandoned conversations.  But that doesn't work because the EntityQuery's entityManager is no longer valid on postback.


      So, how are you doing showing a dataTable and calling methods from commandLink or s:link actions on the rows?  In particular, how do you scope the various components that are involved? 


      Is there a way to use EntityQuery to get a @DataModel that can live in Page scope while still making pagination functional?  Or do your search pages just use a conversation that gets abandoned when the user clicks on a row's action or navigates away? 


      -Confused