View Javadoc

1   /*
2    * $Id: LoggedOff.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>loggedoff.jsp</code> page.</p>
35   */
36  
37  public class LoggedOff {
38  
39  
40      // ------------------------------------------------------ Instance Variables
41  
42  
43      private static final Log log = LogFactory.getLog(LoggedOff.class);
44  
45  
46      // ----------------------------------------------------------------- Actions
47  
48  
49      /**
50       * <p>Begin the process of registering a new user.</p>
51       */
52      public String register() {
53  
54          FacesContext context = FacesContext.getCurrentInstance();
55          if (log.isDebugEnabled()) {
56              log.debug("register(" + context + ")");
57          }
58          forward(context, "/editRegistration.do?action=Create");
59          return (null);
60  
61      }
62  
63  
64      /**
65       * <p>Begin the process of logging on.</p>
66       */
67      public String logon() {
68  
69          FacesContext context = FacesContext.getCurrentInstance();
70          if (log.isDebugEnabled()) {
71              log.debug("logon(" + context + ")");
72          }
73          forward(context, "/editLogon.do");
74          return (null);
75  
76      }
77  
78  
79      // --------------------------------------------------------- Private Methods
80  
81  
82      /**
83       * <p>Forward to the specified URL and mark this response as having
84       * been completed.</p>
85       *
86       * @param context <code>FacesContext</code> for the current request
87       * @param url Context-relative URL to forward to
88       *
89       * @exception FacesException if any error occurs
90       */
91      private void forward(FacesContext context, String url) {
92  
93          try {
94              context.getExternalContext().dispatch(url);
95          } catch (IOException e) {
96              throw new FacesException(e);
97          } finally {
98              context.responseComplete();
99          }
100 
101     }
102 
103 
104 }