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