Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify rewrite pattern in pages.xml

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

like image 379
Achaius Avatar asked Jan 07 '11 09:01

Achaius


1 Answers

  • 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. :-)

like image 52
Shervin Asgari Avatar answered Oct 02 '22 14:10

Shervin Asgari