Closed rider87 closed 2 years ago
Absolutely:
@Override
public Configuration getConfiguration(final ServletContext context)
{
return ConfigurationBuilder.begin()
.addRule(Join.path("/{page}").to("/{page}.xhtml"))
.addRule(Join.path("/{path1}/{page}").to("/{path1}/{page}.xhtml"))
.addRule(Join.path("/{path1}/{path2}/{page}").to("/{path1}/{path2}/{page}.xhtml"));
}
Etc.
That should do what you're looking for without being too complicated.
See more docs here: https://github.com/ocpsoft/rewrite/blob/master/documentation/src/main/asciidoc/configuration/mapping.asciidoc
this means if I have different folders:
I need to configure all like this:
@Override public Configuration getConfiguration(final ServletContext context) { return ConfigurationBuilder.begin() .addRule(Join.path("/common/{page}").to("/common/{page}.xhtml")) .addRule(Join.path("/portal/{page}").to("/portal/{page}.xhtml")) .addRule(Join.path("/admin/{page}").to("/admin/{page}.xhtml")) }
It´s not a big deal... I´m just wondering, if there is also a general rule for all xhtml pages, which just remove the .jsf or .xhtml
Not at all. The configuration I posted will do what you are asking, for all /*/*.xhtml
pages.
you mean 1:1 this?
@Override public Configuration getConfiguration(final ServletContext context) { return ConfigurationBuilder.begin() .addRule(Join.path("/{page}").to("/{page}.xhtml")) .addRule(Join.path("/{path1}/{page}").to("/{path1}/{page}.xhtml")) .addRule(Join.path("/{path1}/{path2}/{page}").to("/{path1}/{path2}/{page}.xhtml")); }
Yes. If you really want to do something that matches all pages, and doesn't care about path "depth", this should work as well:
@Override
public Configuration getConfiguration(final ServletContext context)
{
return ConfigurationBuilder.begin()
.addRule(Join.path("/{*}").to("/{*}.xhtml"));
}
Just be careful because this rule will also match non xhtml resources and files.
So you may want to combine it with something like this:
@Override
public Configuration getConfiguration(final ServletContext context)
{
return ConfigurationBuilder.begin()
.addRule(Join.path("/{*}").to("/{*}.xhtml"))
.when(Resource.exists("/{*}.xhtml));;
}
Closing this as the question has been answered. Thanks!
Hi,
The forum is not working anymore (only Spam). Therefore I will ask my question here:
Is there a general rule to remove extensions for .jsf and .xhtml ? Omnifaces is doing this, but is not that powerful as Rewrte... I would like to have also a few extra rules...
Example: /portal/mypage.jsf will be than /portal/mypage
How can I do that?