问题
Using Pretty Faces 3, I have some mappings like these:
<url-mapping id="search">
<pattern value="/search" />
<view-id value="/views/search.xhtml" />
</url-mapping>
<url-mapping id="edit">
<pattern value="/edit" />
<view-id value="/views/edit.xhtml" />
</url-mapping>
Is there any way to define all them using some wildcard, like this?
<url-mapping id="generic">
<pattern value="/*" />
<view-id value="/views/$1.xhtml" />
</url-mapping>
I know is possible to use EL in the view-id value, but I can manage it to work.
回答1:
Its currently not possible to use a wildcard like this.
However as you already mentioned you could use a dynaview (EL expression for the view-id) to achieve something similar. We recently fixed a bug that prevented something like this to work correcty. Perhaps you could give 3.3.1-SNAPSHOT a try. My guess is that it will work fine now. Feel free to post a message on the forums if you have any further problems.
回答2:
You might be better off using Rewrite which lets you do more powerful configuration:
https://github.com/ocpsoft/socialpm/blob/master/web/src/main/java/com/ocpsoft/socialpm/URLRewriteConfiguration.java
.addRule(Join.path("/{page}").to("/views/{page}.xhtml"))
来源:https://stackoverflow.com/questions/7026232/pretty-faces-generic-url-mapping