5 Replies Latest reply on Sep 24, 2009 4:00 PM by Frank Upgang

    Propagating Request Parameters

    Miguel Cohnen Newbie

      Hi, I have read Chapter 6.4 regarding 'Propagating Page Parameters', but I still don't get it. This is what I'm trying to do;


      I have a site with a page parameter, lets say, itemId. So the url should be something like:




      http://SERVER/APP/item.seam?itemId=3





      This url starts a conversation scoped Home Object (ItemHome). I have a form in there for some fields, and then I want a save link. This save link calls the itemHome.persist method. Here we have the problem.


      - If I use a s:link for saving, my itemId page param is propagated, but also some ugly params (cid and actionMEthod stuff)
      - If I user h:commandLink, the param itemId is not propagated.


      I have tried adding


      <param name="itemId"/>



      to my pages.xml description but it's not working.


      What I want is that the resulting url is the same I had when I accessed the site:


      http://SERVER/APP/item.seam?itemId=3



      Thank you very much for your help! If you need more info, or I haven't been clear enough... just let me know!

        • 1. Re: Propagating Request Parameters
          Aravind Ksr Newbie
          Pass parameter like below. If you want to run in same workspace or conversation also conversationId.

            <h:commandLink value="Open" action="#{commandLinkAction.getMetadata}">
                <s:conversationId />
                <f:param name="itemId" value="itemIdValue" />                     
            </h:commandLink>

          Let me know if you have any issues.

          • 2. Re: Propagating Request Parameters
            Miguel Cohnen Newbie

            Hi,
            Thank you for your answer, but it is still not working.
            With your approach, what you manage is to pass the parameter so that it is available for your action


            #{commandLinkAction.getMetadata}



            to use. But the resultant url after clicking that link is not containing itemId as paramter! I have made a simple example:


            hello.xhtml



            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <f:view xmlns="http://www.w3.org/1999/xhtml"
               xmlns:f="http://java.sun.com/jsf/core"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:s="http://jboss.com/products/seam/taglib"
               contentType="text/html">
            <html>
               <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                  <title>Hello</title>
               </head>
               <body>
                         <h:form>
                         --#{helloAction.text}--
                  <h:commandLink action="#{helloAction.sayHello}" value="Say Hello">
                       <f:param name="helloId" value="#{helloAction.helloId}"/>
                  </h:commandLink>
                  </h:form>
               </body>
            </html>
            </f:view>



            HelloAction.java




            @Name("helloAction")
            @Scope(ScopeType.CONVERSATION)
            public class HelloAction {
                 @RequestParameter
                 private Long helloId;
                 
                 private String text = "";
                 
                 public String getText(){
                      return text;
                 }
                 
                 @Begin(join=true)
                 public void sayHello(){
                      text = "Hello World - "+helloId;
                 }
            
                 public Long getHelloId() {
                      return helloId;
                 }
            
                 public void setHelloId(Long helloId) {
                      this.helloId = helloId;
                 }
            }



            If I call the url


            http://SERVER/APP/hello.seam?helloId=10



            , I receive this screen:



            ---- Say Hello



            When I click in the link I get this one:



            --Hello World - 10-- Say Hello



            Which is fine, but the url is now


            http://SERVER/APP/hello.seam



            The paramter is missing!!! I need the url to be the same than before. Using s:link I have the same url, but it also appends some other info (actionMethod... cid...) That i don't want in my url.


            Hope this clarifies my proble a bit.







            • 3. Re: Propagating Request Parameters
              Frank Upgang Newbie

              You could perform a redirect to the same page after your action method is invoked to restore the URL plus helloId.


              <navigation from-action="#{helloAction.sayHello}">
                   <redirect view-id="#{view.viewId}" />
              </navigation>


              The helloId should be a page parameter.

              • 4. Re: Propagating Request Parameters
                Miguel Cohnen Newbie

                Thank you Frank. That worked great! Is this the recommended way doing this? I mean, is this the recommended way of doing redirect after post? Anyway, it is damn simple and clean. I like it!


                Thank you VERY MUCH!

                • 5. Re: Propagating Request Parameters
                  Frank Upgang Newbie

                  This approach to get bookmarkable URLs is described in the Seam Reference (1.9.2. Bookmarkable search results page). Perhaps, the redirect is a problem in some cases: page scoped components get lost, I think, page actions are executed again. At least for my use cases, it worked fine.