views:

12

answers:

1

I have 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?

A: 

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.

BalusC