5

I am having many xhtml files in several folders. I want to rewrite the url as

from http://localhost:8080/folder1/file1.seam to http://localhost:8080/folder1/file1

In file1.page.xml I gave

<rewrite pattern="/folder1/file1" />

The above provided me with the correct pattern. But i have many files and i don't want to specify this rewrite pattern in every page.xml file. Is there any way to specify this in pages.xml?

EDIT:

http://localhost:8080/folder2/file2.seam to http://localhost:8080/folder2/file2
http://localhost:8080/folder3/file3.seam to http://localhost:8080/folder3/file3

More samples of my translation

Achaius
  • 5,904
  • 21
  • 65
  • 122

2 Answers2

8
  • Rewriting occurs based on rewrite patterns found for views in pages.xml

  • Seam URL rewriting does both incoming and outgoing URL rewriting based on the same pattern

Example:

<page view-id="/home.xhtml">
  <rewrite pattern="/home" />
</page>
  • any incoming request for /home will be sent to /home.xhtml
  • any link generated that would normally point to /home.seam will instead be rewritten as /home
  • Rewrite patterns only match the portion of the URL before the query parameters

  • Both these will be matched

    • /home.seam?conversationId=13
    • /home.seam?color=red

Rewrite rules can take these query paramters into consideration

<page view-id="/home.xhtml">
  <rewrite pattern="/home/{color}" />
  <rewrite pattern="/home" />
</page>

Incoming request for /home/red will be served as if it were a request for /home.seam?color=red

If color is a page parameter an outgoing URLr /home.seam?color=blue would output as /home/blue

Remember:

  • Rules are processed in order

  • List more specific rules before more general rules

If you want to hide the conversation id, you can do like this:

<page view-id="/search.xhtml">
  <rewrite pattern="/search-{conversationId}" />
  <rewrite pattern="/search" />
</page>

Now /search.seam?conversationId=16would be written as /search-16

If you want to match multiple pages use wildcards

<page login-required="true" view-id="/admin/*">

Hope this helps

Update

To answer your update question.

You can create wildcard rewriting with external rewriting but not with Seam's URL rewriting. With the view-based rewriting you would need to declare a pattern for each view id as you have described your self. Sorry, but that just the way the cookie crumbles. :-)

Shervin Asgari
  • 23,901
  • 30
  • 103
  • 143
  • thanks for your response. Most of your discussion surrounds around modifying page.xml for URLs with page parameters. I have modified my question and have added additional URLs, our intention is to just truncate seam on all occurences and we aren't worried about the query parameters right now and we are looking for a generic mechanism to apply this on pages.xml file. Your thread contains a snippet, where you had mentioned that login-required=true for all pages under "admin" folder. I am still unable to get the re-write working for all of my folders using a simple re-write rule. – Achaius Jan 11 '11 at 12:02
2

yes, there is. Look at here.

zinan.yumak
  • 1,590
  • 10
  • 9
  • Iam not looking for hide query parameters. Just i want to hide the extension .seam from url. This is not working. – Achaius Jan 07 '11 at 12:04