Another very important feature we would like to support is the URL rewriting this is very useful to make simple URLs for both SEO optimization and users.
Seam gives very good support for this by just adding the support to the components.xml
file:
<components ...> ... <web:rewrite-filter view-mapping="*.seam"/> ... </components>
Now you have to tell, for every page, how to rewrite it: you can do both by using pages.xml
file or a single<page_name>.page.xml
file for every page.
We are going to use the single page approach: let's create a file called home.page.xml
inside the /view/
directory and insert the following code into it:
<?xml version="1.0" encoding="UTF-8"?> <page xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd" login-required="true"> <rewrite pattern="/home" /> </page>
Apart from the page definition, you can see that the tag to define the rewrite pattern is highlighted you don't have to change anything to view the links, for example in the menu points to the .xhtml
page, then Seam will rewrite it in the right way: try it yourself!
Another useful feature is that we can use param
inside the pattern. We'll see it in more detail in the next chapter, for now let's see a simple example:
<?xml version="1.0" encoding="UTF-8"?> <page xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd" login-required="true"> <param name="userId" required="true" /> <rewrite pattern="/myPage-{myParam}" /> </page>
As you can see, we can include param
inside the pattern and Seam will make it work automatically; very simple!
We will see more concrete use cases of param
in rewrite patterns in the following chapters.
The insertion of URL rewrite patterns for every page that we have created till now is left as an exercise for the reader.
18.118.189.251