2 Replies Latest reply on Jul 9, 2009 8:32 AM by Lukasz Rozek

    URL rewriting for action attribute in form

    Lukasz Rozek Newbie

      I have defined rewrite pattern for custom page:


      <rewrite pattern="/users/{userId}/offers/add_s1" />



      There is a form rendered on that screen, with given markup as follows:


      <form id="j_id24" name="j_id24" method="post" 
      action="/onlinerentalsystem-portal/users/offers/add/add_step1.seam" 
      enctype="application/x-www-form-urlencoded">
      ...
      </form>



      So as you can see the rewriting failed, cause action's value has absolute resource's path on the server, instead of rewrited. The problem occurs when someone fills the form in with invalid data, so after submitting, validation failes, causing changing the url in your browser.



      I changed rewrite pattern to

      <rewrite pattern="/users/offers/add_s1" />

      so as you can see I gave up
      using parameter. In this case rewriting successed, resultling with
      <form id="j_id24" name="j_id24" method="post" 
      action="/onlinerentalsystem-portal/users/offers/add_s1" 
      enctype="application/x-www-form-urlencoded">
      ...
      </form>



      I did some debbuging to find out what causes the problem. I found out that form renderer calls encodeURL(String url) on RewritingRespone, passing url without parameters.

      /onlinerentalsystem-portal/users/offers/add/add_step1.seam

      insted of
      /onlinerentalsystem-portal/users/offers/add/add_step1.seam?userId=1



      My problem is, that I don't know how to include parameters for action attribute in form.
      Can anyone give me some hint or workaround how to solve the issue.


      Thanks in advance









        • 1. Re: URL rewriting for action attribute in form
          Lukasz Rozek Newbie

          In order to to have pretty url we have to redirect after post, which is after invoke application phase and when called method finish successfully. So for the outcome we define navigation plus redirection. In my case invoke application is skipped due to validation failure. Can I somehow force redirection after each POST no mater if I full cycle occured or not ??


          If I redirected after validation failure I would loose all submitted values and messages, so user wouldn't find out what he has to correct, and refilled form in.

          • 2. Re: URL rewriting for action attribute in form
            Lukasz Rozek Newbie

            I noticed that I have this problem on each screen where I use params in page.xml. It is the same for AJAX requests. It uses as target of POST request, absolute path on server instead of rewritten. Every time validation fails on these screens, URL in my browser gets broken. if someone bookmarks this URL or sends GET, he will get error (cause missing parameters). How do you handle this issue ??