Do I need to make a custom regex pattern to match URLs when I have the following mapping (example):
<url-mapping id="approvedQuestions">
<pattern>/questions/approved/#{viewOption}/</pattern>
<view-id>/approved.xhtml</view-id>
</url-mapping>
where the viewoption-portion should also match when the user does NOT end the URL with '/'? And is it possible to supply some kind of default value if the don't add the viewOption portion at all?
And if I the viewOption is a enum, is it possible to lowercase the parameter? Now I have to write uppercase in to make it work.
You can use a custom regex to do this type of, but I recommend using a url-rewrite rule to append a trailing slash if one is missing. You should pick one URL (with or without the '/' at the end) otherwise you are actually serving up the same resources with two distinct addresses, and you will be punished by search engines and other crawlers.
To do this, I would use a rewrite rule such as the following:
<rewrite match="/questions/approved/[^/]+" trailingSlash="append" />
This will cause the server to detect when a '/' is missing from the end of the URL, and it will redirect the request to the proper location, with a '/' at the end.
In order to address your enum issue, this is a bit more complicated. We don't typically recommend binding values directly into enumerations. In this case, you are not actually binding into an enum (I'm guessing,) but are actually binding the literal string URL value into the request scoped EL context. This value is then being extracted somewhere else in your application, and that is where the conversion into an ENUM is taking place.
Until PrettyFaces 4 comes out, I recommend instead binding the value into a String location, then using an action method to do the loading of the correct value yourself, like so:
<url-mapping id="approvedQuestions">
<pattern>/questions/approved/#{params.viewOption}/</pattern>
<view-id>/approved.xhtml</view-id>
<action>#{params.loadViewOption}</action>
</url-mapping>
If you want to try a more advanced URL-rewriting tool, also from OCPsoft, you can use "Rewrite" (http://ocpsoft.com/rewrite/), which is a Java-based URL-rewriting tool, but does not have as much integration with JSF.
PrettyFaces 4 will be based on rewrite as a core, at which point, all of the features you currently use will also be available with the ability to do something more like this, which is what you want if I am not mistaken:
.addRule(Join.path("/questions/approved/{viewOption}").to("/approved.xhtml")
.where("viewOption")
.matches("[^/]+/?")
.transformedBy(TrailingSlash.append())
.transformedBy(To.upperCase())
You would need to create your own transformers because they haven't been defined in the library yet, but that's the general idea. It's much more powerful than what's currently possible with PrettyFaces, but does not provide the same JSF navigation integration, and is a little trickier to configure.
I hope this helps, ~Lincoln