View Javadoc

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