1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.webapp.example;
19
20
21 import java.io.IOException;
22 import javax.faces.FacesException;
23 import javax.faces.context.FacesContext;
24
25
26 /***
27 * <p>Abstract base class for backing beans.</p>
28 */
29
30 abstract class AbstractBacking {
31
32
33
34
35
36 /***
37 * <p>Return the context relative path for the specified action.</p>
38 *
39 * @param context <code>FacesContext</code> for the current request
40 * @param action Name of the requested action
41 */
42 protected StringBuffer action(FacesContext context, String action) {
43
44
45 StringBuffer sb = new StringBuffer(action);
46 sb.append(".do");
47 return (sb);
48
49 }
50
51
52 /***
53 * <p>Forward to the specified URL and mark this response as having
54 * been completed.</p>
55 *
56 * @param context <code>FacesContext</code> for the current request
57 * @param url Context-relative URL to forward to
58 *
59 * @exception FacesException if any error occurs
60 */
61 protected void forward(FacesContext context, String url) {
62
63 try {
64 context.getExternalContext().dispatch(url);
65 } catch (IOException e) {
66 throw new FacesException(e);
67 } finally {
68 context.responseComplete();
69 }
70
71 }
72
73
74 /***
75 * <p>Return the context relative base URL for the "logoff"
76 * action.</p>
77 *
78 * @param context <code>FacesContext</code> for the current request
79 */
80 protected StringBuffer logoff(FacesContext context) {
81
82 return (action(context, "/logoff"));
83
84 }
85
86
87 /***
88 * <p>Return the context relative base URL for the "logon"
89 * action.</p>
90 *
91 * @param context <code>FacesContext</code> for the current request
92 */
93 protected StringBuffer logon(FacesContext context) {
94
95 return (action(context, "/logon"));
96
97 }
98
99
100 /***
101 * <p>Return the context relative base URL for the "edit registration"
102 * action.</p>
103 *
104 * @param context <code>FacesContext</code> for the current request
105 */
106 protected StringBuffer registration(FacesContext context) {
107
108 return (action(context, "/editRegistration"));
109
110 }
111
112
113 /***
114 * <p>Return the context relative base URL for the "edit subscriptions"
115 * action.</p>
116 *
117 * @param context <code>FacesContext</code> for the current request
118 */
119 protected StringBuffer subscription(FacesContext context) {
120
121 return (action(context, "/editSubscription"));
122
123 }
124
125
126 }