01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/app/src/java/org/sakaiproject/jsf/app/SakaiNavigationHandler.java $
03: * $Id: SakaiNavigationHandler.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
04: **********************************************************************************
05: *
06: * Copyright (c) 2003, 2004 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.jsf.app;
21:
22: import javax.faces.application.NavigationHandler;
23: import javax.faces.context.FacesContext;
24: import javax.servlet.http.HttpServletRequest;
25:
26: /**
27: * <p>
28: * SakaiNavigationHandler catches the response that is being redirected to preserve the faces messages for the return request.
29: * </p>
30: *
31: */
32: public class SakaiNavigationHandler extends NavigationHandler {
33: /** The other navigation handler. */
34: protected NavigationHandler m_chain = null;
35:
36: /**
37: * Construct.
38: */
39: public SakaiNavigationHandler() {
40: }
41:
42: /**
43: * Construct.
44: */
45: public SakaiNavigationHandler(NavigationHandler chain) {
46: m_chain = chain;
47: }
48:
49: /**
50: * Handle the navigation
51: *
52: * @param context
53: * The Faces context.
54: * @param fromAction
55: * The action string that triggered the action.
56: * @param outcome
57: * The logical outcome string, which is the new tool mode, or if null, the mode does not change.
58: */
59: public void handleNavigation(FacesContext context,
60: String fromAction, String outcome) {
61: m_chain.handleNavigation(context, fromAction, outcome);
62:
63: // if we have a redirect scheduled, we need to preserve the messages
64: // if we are coming from the Sakai RequestFilter, and a redirect was requested, the request object
65: // will have this attribute set.
66: HttpServletRequest req = (HttpServletRequest) context
67: .getExternalContext().getRequest();
68: if (req.getAttribute("sakai.redirect") != null) {
69: // save messages from the context for restoration on the next rendering
70: MessageSaver.saveMessages(context);
71: }
72: }
73: }
|