14 Replies Latest reply on Nov 8, 2006 3:11 PM by iradix

    Seam Page Parameters

    iradix

      I have several conversational components that retrieve a List of search results and outject them as DataModels. To make my life easier, I had them all subclass an object with the ability to paginate. To summarize, it basically just keeps track of an offset into the data and a limit (how many results are displayed per page) then I let the DataTable component control the display. To move back and forth there are action methods in the superclass that either add or subtract the limit from the offset. My problem is that because the superclass is generic, it does not know the symbolic view-id to redirect back to the results page and therefore I use:

      FacesContext.getCurrentInstance().getViewRoot().getViewId()


      As the return. Unfortunately, this method does not cause seam to add the page parameter that I've defined (containing the offset) to the redirect. Is there a reason for this? It binds the offset into the search bean fine on a GET, it just won't add it to the redirect. The documentation states that page parameters are added for redirects to symbolic views that contain the element. Is that the only way they work? Is there a reason that eplicitly specifying a view-id won't work?

        • 1. Re: Seam Page Parameters
          iradix

          Ok, let me amend that. I just tried it with the page action returning a symbolic view-id and it still doesn't get added as a query parameter during the redirect. I'm using 1.1 beta. Am I missing something?

          • 2. Re: Seam Page Parameters
            pmuir

            I may misunderstand what you are about, but can't you return null from the action method to stay on the same page? Not sure if that fixes the page parameters problem...

            • 3. Re: Seam Page Parameters
              iradix

              I believe returning null would result in a forward to the same page, I'm looking for a redirect. Returning a view-id that begins with a / (like /products/search.jsf) does seem to redirect correctly. Does anyone have page parameters working? I've started looking through the source and it seems like they are appended by the SeamRedirectFilter, which I'm using.

              • 4. Re: Seam Page Parameters
                gavin.king

                This should work fine. SeamRedirectFilter does the job of appending them, so try putting a breakpoint in the sendRedirect() method to see why its not working for you.

                • 5. Re: Seam Page Parameters
                  iradix

                  It looks like it's a bug. The method

                  public static String getViewId(String url)
                  in the SeamRedirectFilter uses
                  url.substring(contextPath.length(), getParamLoc(url) - suffix.length() + 1) + suffix;
                  to calculate the viewId, but that seems to clip the last character off. I think that
                  url.substring(contextPath.length(), getParamLoc(url) - suffix.length() + 2) + suffix;
                  is correct and it works after I made the change locally.

                  • 6. Re: Seam Page Parameters
                    iradix

                    Wait, I take that back.

                    url.substring(contextPath.length(), getParamLoc(url) - extension.length() + 1) + suffix;


                    Is probably what you were looking for... I'll test that.

                    • 7. Re: Seam Page Parameters
                      iradix

                      Wrong again. Looks like the winning combo is:

                      url.substring(contextPath.length(), getParamLoc(url) - extension.length()) + suffix;


                      They way it was probably worked because you were going from a .seam URL to a 3 character version (.jsp maybe?) whereas I'm going from .jsf to .xhtml for facelets.

                      • 8. Re: Seam Page Parameters
                        gavin.king

                        Thanks, appreciated. I've committed your fix.

                        • 9. Re: Seam Page Parameters
                          iradix

                          No problem. Happy to help.

                          • 10. Re: Seam Page Parameters
                            iradix

                            I'm running into another problem. It seems that the converter specified in pages.xml is used to convert from String to Object, but not from Object to String. I don't suppose that's by design? The method I'm looking at is:

                            public Map<String, Object> getParameters(String viewId, Set<String> overridden)
                             {
                             Map<String, Object> parameters = new HashMap<String, Object>();
                             for ( PageParameter pageParameter: getPage(viewId).pageParameters )
                             {
                             if ( !overridden.contains(pageParameter.name) )
                             {
                             Object value = pageParameter.valueBinding.getValue();
                             if (value!=null)
                             {
                             parameters.put(pageParameter.name, value);
                             }
                             }
                             }
                             return parameters;
                             }


                            Which seems to just retrieve the value from the page parameter value binding without passing it through the converter at all.

                            • 11. Re: Seam Page Parameters
                              gavin.king

                              Nice catch, I'll fix it.

                              • 12. Re: Seam Page Parameters
                                gavin.king
                                • 13. Re: Seam Page Parameters
                                  gavin.king

                                  Done in CVS, please test this for me. thanks

                                  • 14. Re: Seam Page Parameters
                                    iradix

                                    Looks good. Thanks.