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