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