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 javax.faces.component.UIData;
27 import javax.faces.context.FacesContext;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31
32
33
34
35
36 public class RegistrationBacking extends AbstractBacking {
37
38
39
40
41
42 private static final Log log = LogFactory.getLog(RegistrationBacking.class);
43
44
45
46
47
48 private UIData table = null;
49
50
51
52
53
54 public UIData getTable() {
55
56 return (this.table);
57
58 }
59
60
61
62
63
64
65
66 public void setTable(UIData table) {
67
68 this.table = table;
69
70 }
71
72
73
74
75
76
77
78
79
80 public String create() {
81
82 if (log.isDebugEnabled()) {
83 log.debug("create()");
84 }
85 FacesContext context = FacesContext.getCurrentInstance();
86 StringBuffer url = subscription(context);
87 url.append("?action=Create");
88 url.append("&username=");
89 User user = (User)
90 context.getExternalContext().getSessionMap().get("user");
91 url.append(user.getUsername());
92 forward(context, url.toString());
93 return (null);
94
95 }
96
97
98
99
100
101 public String delete() {
102
103 if (log.isDebugEnabled()) {
104 log.debug("delete()");
105 }
106 FacesContext context = FacesContext.getCurrentInstance();
107 StringBuffer url = subscription(context);
108 url.append("?action=Delete");
109 url.append("&username=");
110 User user = (User)
111 context.getExternalContext().getSessionMap().get("user");
112 url.append(user.getUsername());
113 url.append("&host=");
114 Subscription subscription = (Subscription)
115 context.getExternalContext().getRequestMap().get("subscription");
116 url.append(subscription.getHost());
117 forward(context, url.toString());
118 return (null);
119
120 }
121
122
123
124
125
126 public String edit() {
127
128 if (log.isDebugEnabled()) {
129 log.debug("edit()");
130 }
131 FacesContext context = FacesContext.getCurrentInstance();
132 StringBuffer url = subscription(context);
133 url.append("?action=Edit");
134 url.append("&username=");
135 User user = (User)
136 context.getExternalContext().getSessionMap().get("user");
137 url.append(user.getUsername());
138 url.append("&host=");
139 Subscription subscription = (Subscription)
140 context.getExternalContext().getRequestMap().get("subscription");
141 url.append(subscription.getHost());
142 forward(context, url.toString());
143 return (null);
144
145 }
146
147
148
149
150
151
152 public String update() {
153
154 if (log.isDebugEnabled()) {
155 log.debug("update()");
156 }
157
158 FacesContext context = FacesContext.getCurrentInstance();
159
160
161
162 try {
163 UserDatabase database = (UserDatabase)
164 context.getExternalContext().getApplicationMap().
165 get(Constants.DATABASE_KEY);
166 database.save();
167 } catch (Exception e) {
168 log.error("Database save", e);
169 }
170
171
172 StringBuffer sb = registration(context);
173 sb.append("?action=Edit");
174 forward(context, sb.toString());
175 return (null);
176
177 }
178
179
180 }