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>loggedon.jsp</code> page.</p>
39 */
40
41 @Named
42 @RequestScoped
43 public class LoggedOn {
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(LoggedOn.class);
54
55
56 // ----------------------------------------------------------------- Actions
57
58
59 /**
60 * <p>Begin the process of logging off.</p>
61 */
62 public String logoff() {
63
64 FacesContext context = FacesContext.getCurrentInstance();
65 LOG.debug("logoff({})", context);
66 forward(context, "/logoff.do");
67 return (null);
68
69 }
70
71
72 // --------------------------------------------------------- Private Methods
73
74
75 /**
76 * <p>Forward to the specified URL and mark this response as having
77 * been completed.</p>
78 *
79 * @param context <code>FacesContext</code> for the current request
80 * @param url Context-relative URL to forward to
81 *
82 * @exception FacesException if any error occurs
83 */
84 private void forward(FacesContext context, String url) {
85
86 try {
87 context.getExternalContext().dispatch(url);
88 } catch (IOException e) {
89 throw new FacesException(e);
90 } finally {
91 context.responseComplete();
92 }
93
94 }
95 }