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