4 Replies Latest reply on Oct 19, 2010 5:11 PM by Craig Bensemann

    Wildcard URLs in pages.xml?

    Daniel Rowe Newbie
      I'm trying have my application recognize "custom" URLs, for example:

         http://www.domain.com/appname/town/TOWN_NAME 

      where TOWN_NAME doesn't actually point to an existing .xhtml page.
      In other words, I want to display a page that is common to all towns, but looks like the town has its own URL.

      I though I could do this in pages.xml with something like:

          <page view-id="/town/*" action="#{TownManager.initTownInfo()}">
          </page>

      which would call the TownManager.initTownInfo() method and lookup town information based on the URL, then redirect to a common town.xhtml page that has custom information available to it from the initTownInfo() method.

      What I'm finding is that the wildcard in pages.xml (page view-id="/town/*) doesn't cause the action method to execute, possibly because there isn't actually an existing .xhtml page with a town name that matches.

      Has anyone else dealt with this type of thing?

      Thanks!
        • 1. Re: Wildcard URLs in pages.xml?
          Leo van den berg Master

          Hi,


          maybe the Resteasy components can be helpful for you if it is your objective to just execute a single GET with a meaningful URL, which should return a specfic result.It works great althoufgh it is not really meant to return html-pages, but more to create simple webservices. Another posibility would be to use natural conversations. It's not exactly what you describe, but it gives a recognizable URL.


          Leo


           

          • 2. Re: Wildcard URLs in pages.xml?
            Daniel Rowe Newbie

            Thanks, Leo.  That was enough to get me looking into URL rewriting, which I think will handle the issue.  I'll try that out tomorrow...

            • 3. Re: Wildcard URLs in pages.xml?
              Daniel Rowe Newbie
              Yes, urlrewrite is what I needed.


              pages.xml:

                  <page view-id="/town.xhtml" action="#{TownManager.initTownInfo}">
                  </page>


              urlrewrite.xml:

                 <urlrewrite>
                    <rule>
                       <from>^/town/(.*)</from>
                       <to>/town.seam?townname=$1</to>
                    </rule>
                 </urlrewrite>
              • 4. Re: Wildcard URLs in pages.xml?
                Craig Bensemann Novice

                Did you know you can also specify your rewrite rules in your pages.xml?


                    <page view-id="/pages/person/viewPerson.xhtml" login-required="true">
                        <description>View a person</description>
                        <begin-conversation join="true"/>
                        <param name="personId" value="#{viewPersonController.personId}"/>
                        <rewrite pattern="/pages/person/viewPerson-{cid}/{personId}"/>
                        <rewrite pattern="/pages/person/viewPerson/{personId}"/>
                        <rewrite pattern="/pages/person/viewPerson"/>
                    </page>
                



                So in this example the url /pages/person/viewPerson.seam will be rewritten as one of the three rules specified (they are evaluated top to bottom and the first matching rule is used.)


                /pages/person/viewPerson-1/123 This is an example of the first rule where 1 is the conversation id parameter and 123 is the personId parameter.


                /pages/person/viewPerson/123 When there is no conversation id (second rule)


                /pages/person/viewPerson When there is no conversation id or personId (third rule)