Can I use a JSF navigation rule in a servlet for redirection?
I ha开发者_StackOverflow社区ve to use a few servlets in my Web application. The servlets perform a bit of processing and then redirect the user to an xhtml page.
I already have navigation rules in my app, which I'd like to re-use in my servlet.
Example:
<navigation-case>
<from-outcome>bookingFailed</from-outcome>
<to-view-id>/SecureUser/Reservation/New/BookingFailed.xhtml</to-view-id>
<redirect/>
</navigation-case>
Now inside the servlet, I'd like to use something like:
response.sendRedirect("bookingFailed");
instead of
response.sendRedirect("faces/SecureUser/Reservation/New/BookingFailed.xhtml");
How can I go about doing this?
Since servlets doesn't run inside the JSF context, you really need to parse all the <navigation-case>
entries out of the faces-config.xml
file into a Map
yourself, so that you can end up doing:
response.sendRedirect("faces" + navigationCases.get("bookingFailed"));
The builtin JAXP and XPath API's may be useful in this.
That said, you'd really consider to do JSF context-dependent processing inside the JSF context rather than in a plain vanilla servlet. Use the constructor of a managed bean or a PhaseListener
listening on RESTORE_VIEW
.
精彩评论