View Javadoc

1   /*
2    * Copyright 1999-2002,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.struts.webapp.example2;
19  
20  
21  import java.io.IOException;
22  import javax.faces.FacesException;
23  import javax.faces.context.FacesContext;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  
28  /***
29   * <p>Backing bean for the <code>loggedon.jsp</code> page.</p>
30   */
31  
32  public class LoggedOn {
33  
34  
35      // ------------------------------------------------------ Instance Variables
36  
37  
38      private static final Log log = LogFactory.getLog(LoggedOn.class);
39  
40  
41      // ----------------------------------------------------------------- Actions
42  
43  
44      /***
45       * <p>Begin the process of logging off.</p>
46       */
47      public String logoff() {
48  
49          FacesContext context = FacesContext.getCurrentInstance();
50          if (log.isDebugEnabled()) {
51              log.debug("logoff(" + context + ")");
52          }
53          forward(context, "/logoff.do");
54          return (null);
55  
56      }
57  
58  
59      // --------------------------------------------------------- Private Methods
60  
61  
62      /***
63       * <p>Forward to the specified URL and mark this response as having
64       * been completed.</p>
65       *
66       * @param context <code>FacesContext</code> for the current request
67       * @param url Context-relative URL to forward to
68       *
69       * @exception FacesException if any error occurs
70       */
71      private void forward(FacesContext context, String url) {
72  
73          try {
74              context.getExternalContext().dispatch(url);
75          } catch (IOException e) {
76              throw new FacesException(e);
77          } finally {
78              context.responseComplete();
79          }
80  
81      }
82  
83  
84  }