1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.webapp.example2;
19
20
21 import java.io.IOException;
22 import javax.faces.FacesException;
23 import javax.faces.context.FacesContext;
24
25
26 /***
27 * <p>Backing bean for the <code>registration.jsp</code> page.</p>
28 */
29
30 public class RegistrationBacking {
31
32
33
34
35
36
37
38
39 public String getDeleteLabel() { return ("Delete"); }
40 public String getEditLabel() { return ("Edit"); }
41
42
43
44
45
46 /***
47 * <p>Create a new subscription.</p>
48 */
49 public String create() {
50
51 FacesContext context = FacesContext.getCurrentInstance();
52 StringBuffer url = base(context);
53 url.append("?action=Create");
54 url.append("&username=");
55 User user = (User)
56 context.getExternalContext().getSessionMap().get("user");
57 url.append(user.getUsername());
58 forward(context, url.toString());
59 return (null);
60
61 }
62
63
64 /***
65 * <p>Delete an existing subscription.</p>
66 */
67 public String delete() {
68
69 FacesContext context = FacesContext.getCurrentInstance();
70 StringBuffer url = base(context);
71 url.append("?action=Delete");
72 url.append("&username=");
73 User user = (User)
74 context.getExternalContext().getSessionMap().get("user");
75 url.append(user.getUsername());
76 url.append("&host=");
77 Subscription subscription = (Subscription)
78 context.getExternalContext().getRequestMap().get("subscription");
79 url.append(subscription.getHost());
80 forward(context, url.toString());
81 return (null);
82
83 }
84
85
86 /***
87 * <p>Edit an existing subscription.</p>
88 */
89 public String edit() {
90
91 FacesContext context = FacesContext.getCurrentInstance();
92 StringBuffer url = base(context);
93 url.append("?action=Edit");
94 url.append("&username=");
95 User user = (User)
96 context.getExternalContext().getSessionMap().get("user");
97 url.append(user.getUsername());
98 url.append("&host=");
99 Subscription subscription = (Subscription)
100 context.getExternalContext().getRequestMap().get("subscription");
101 url.append(subscription.getHost());
102 forward(context, url.toString());
103 return (null);
104
105 }
106
107
108
109
110
111 /***
112 * <p>Return the context relative base URL for the "edit subscriptions"
113 * action.</p>
114 *
115 * @param context <code>FacesContext</code> for the current request
116 */
117 private StringBuffer base(FacesContext context) {
118
119
120 return (new StringBuffer("/editSubscription.do"));
121
122 }
123
124
125 /***
126 * <p>Forward to the specified URL and mark this response as having
127 * been completed.</p>
128 *
129 * @param context <code>FacesContext</code> for the current request
130 * @param url Context-relative URL to forward to
131 *
132 * @exception FacesException if any error occurs
133 */
134 private void forward(FacesContext context, String url) {
135
136 try {
137 context.getExternalContext().dispatch(url);
138 } catch (IOException e) {
139 throw new FacesException(e);
140 } finally {
141 context.responseComplete();
142 }
143
144 }
145
146
147 }