4 Replies Latest reply on Feb 23, 2010 8:55 AM by nimo stephan

    rewrite with param - not REST !

    nimo stephan Master

      Look at the snippet from my pages.xml:



      <page view-id="/test.xhtml" login-required="true">
      <param name="lastname" value="#{user.lastname}"/>
      <rewrite pattern="/test_{lastname}"/>
      </page>




      which produces for example:


      'test_nimo'





      but when I go to the address bar and manually overwrite 'nimo' with 'steve',
      then the link 'teststeve' is shown and the lastname is changed. I do not want that!

      How can I avoid such behaviour ?

      I want, that the link 'test
      steve' is not available, as it is not existing for a user such as 'testnimo'.
      test
      nimo' should only be exist and available.



      How can I do that?

        • 1. Re: rewrite with param - not REST !
          Daniel Hinojosa Master


          but when I go to the address bar and manually overwrite 'nimo' with 'steve', then the link 'teststeve' is shown and the lastname is changed.

          So what you are saying is that the underscore is getting removed when you go to the page?

          • 2. Re: rewrite with param - not REST !
            nimo stephan Master

            hello daniel,


            the underscore is not the matter for my problem.


            The url works and looks like


            www.mypage.com/nimo




            with this pages.xml:


            <page view-id="/actualUser.xhtml" login-required="true">
            <param name="actual_user" value="#{loggedInUser.name}"/>
            <rewrite pattern="/{actual_user}"/>
            </page>




            nimo is the name of the registered user (loggedInUser) and this is stored in a sessions property.


            Now, you go to the site


            www.mypage.com/nimo 



            and within the site there is the same:


            <h:outputText value="Hello #{loggedInUser.name}"/>



            which prints Hello nimo!

            All fine, BUT when I go the addressbar and overwrite

            www.mypage.com/nimo


            with whatever other name

            www.mypage.com/steve

            then the site is again rendered and replaces the value stored in
            loggedInUser from nimo to steve and I will see: Hello stefan!



            How can I avoid such behaviour?
            If the user overwrites the name in the addressbar, the property should not be changed - the site name should be changed.


            How can I do that?

            • 3. Re: rewrite with param - not REST !
              Daniel Hinojosa Master

              You can avoid that by not even having the rewrite pattern:


              pages.xml


              from:


              <page view-id="/actualUser.xhtml" login-required="true">
              <param name="actual_user" value="#{loggedInUser.name}"/>
              <rewrite pattern="/{actual_user}"/>
              </page>
              



              to:


              <page view-id="/actualUser.xhtml" login-required="true"/>
              



              Because if you want this to only work for the person that is logged why make the url dependent on any other name, since you already know who is logged in? Is that what you are looking for, or am I missing something?


              • 4. Re: rewrite with param - not REST !
                nimo stephan Master

                I want a pretty url with the name of the logged in user - so I need to want to use the rewrite pattern.


                Maybe, I have to copy the param name loggedInUser.name to a RequestScope-Variable (for example requestName) - would it be help?




                <param name="actual_user" value="#{loggedInUser.name}"/>



                Or should I use something like PrettyFaces with inbound/outbound url? I have red, that PrettyFaces is also a lot of faster than jboss rewriting as it does not need the two requests for making the rewrite (http://www.slideshare.net/lincolnthree/pretty-bookmarkable-jsf-prettyfaces-presentation). However, I have not tried it with seam yet and I do not know, if JSF 2.0 has some tequniques which eliminates the need of extra lib prettyfaces.