3 Replies Latest reply on Jan 8, 2008 4:05 PM by pmuir

    Page Parameter Pains.

    andygibson

      I have a stateless view page for a widget and multiple lists of widget detail records in data tables in a rich:tab. I pass in the widgetId as a parameter to fetch and display the view, and use page parameters to maintain state in a stateless view as the user interacts with it. I'm finding some nasty side effects of page parameters.

      For each widget detail, I have a rich:tab containing a data table that displays the widget detail and my own little paginator facelet that uses the EntityQuery methods for next, first, last, prev etc... Being stateless, I need to pass the first result for each subdetail each time so the entity query knows where to start displaying results from.

      My pages.xml for the page looks like this :

       <page view-id="widgetView.xhtml">
       <param name="widgetId" value="#{widgetHome.id}" required="false"
       converterId="javax.faces.Long" />
       <param name="subDetailAFirst" required="false"
       value="#{subDetailsAQuery.firstResult}" />
       <param name="subDetailsBFirst" required="false"
       value="#{subDetailsBQuery.firstResult}" />
       </page>
      
      

      (There are 5 sub details each with a tab containing a table and a paginator)

      This works, and works extremely well, it was a piece of cake to develop, and it's times like this that Seam rocks.

      However, it has a problem. Obviously, since I use page params, anytime I do an s:link to the page, Seam tries to add the parameters and since there are none, it creates the EntityQueries to try and obtain the parameter values. Obviously this is not the desired result. This problem also happens for search pages with bookmarkeable results when the search pages are linked from a page, or even worse, a menu which is re-used across a number of pages.

      Normally when you have a link to a page with page parameters for which you know there is no value (i.e. the contactId in the add contact link in the seam contact example), you can add it manually to the s:link so seam doesn't try to add it. This is somewhat acceptable to a point.

      It seems a little clumsy to have to do that for each of the 5 parameters, for every link that references the page, and will need to be modified if I ultimately add a 6th sub detail table with pagination.

      One option is to put it into a conversation and make it stateful which works, but apart from being a little unnecessary, and overkill for a view page, it comes with it's own trickses. When you change tabs, and it involves a datafetch, and you go back to the original tab, the data is nulled out because a sql query flushed the entity manager and nulled out the existing data entities.

      Going back to a stateless solution, it seems that a better option is to make page parameters optional (similar to the required attribute for @In and @Out bijection) so that if the object isn't there, and it is optional, then no object is created and no parameter is added. I couldn't find an existing JIRA, anyone have any thoughts on the matter? Should I not worry about multiple objects being created per request for no reason?

      Cheers,

      Andy Gibson