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.example2;
24
25
26 import java.io.IOException;
27 import javax.faces.FacesException;
28 import javax.faces.context.FacesContext;
29
30
31
32
33
34
35 public class RegistrationBacking {
36
37
38
39
40
41
42
43
44 public String getDeleteLabel() { return ("Delete"); }
45 public String getEditLabel() { return ("Edit"); }
46
47
48
49
50
51
52
53
54 public String create() {
55
56 FacesContext context = FacesContext.getCurrentInstance();
57 StringBuffer url = base(context);
58 url.append("?action=Create");
59 url.append("&username=");
60 User user = (User)
61 context.getExternalContext().getSessionMap().get("user");
62 url.append(user.getUsername());
63 forward(context, url.toString());
64 return (null);
65
66 }
67
68
69
70
71
72 public String delete() {
73
74 FacesContext context = FacesContext.getCurrentInstance();
75 StringBuffer url = base(context);
76 url.append("?action=Delete");
77 url.append("&username=");
78 User user = (User)
79 context.getExternalContext().getSessionMap().get("user");
80 url.append(user.getUsername());
81 url.append("&host=");
82 Subscription subscription = (Subscription)
83 context.getExternalContext().getRequestMap().get("subscription");
84 url.append(subscription.getHost());
85 forward(context, url.toString());
86 return (null);
87
88 }
89
90
91
92
93
94 public String edit() {
95
96 FacesContext context = FacesContext.getCurrentInstance();
97 StringBuffer url = base(context);
98 url.append("?action=Edit");
99 url.append("&username=");
100 User user = (User)
101 context.getExternalContext().getSessionMap().get("user");
102 url.append(user.getUsername());
103 url.append("&host=");
104 Subscription subscription = (Subscription)
105 context.getExternalContext().getRequestMap().get("subscription");
106 url.append(subscription.getHost());
107 forward(context, url.toString());
108 return (null);
109
110 }
111
112
113
114
115
116
117
118
119
120
121
122 private StringBuffer base(FacesContext context) {
123
124
125 return (new StringBuffer("/editSubscription.do"));
126
127 }
128
129
130
131
132
133
134
135
136
137
138
139 private void forward(FacesContext context, String url) {
140
141 try {
142 context.getExternalContext().dispatch(url);
143 } catch (IOException e) {
144 throw new FacesException(e);
145 } finally {
146 context.responseComplete();
147 }
148
149 }
150
151
152 }