KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > example > RegistrationBacking


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.struts.webapp.example;
19
20
21 import javax.faces.component.UIData;
22 import javax.faces.context.FacesContext;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26
27 /**
28  * <p>Backing bean for the <code>registration.jsp</code> page.</p>
29  */

30
31 public class RegistrationBacking extends AbstractBacking {
32
33
34     // -------------------------------------------------------- Static Variables
35

36
37     private static final Log log = LogFactory.getLog(RegistrationBacking.class);
38
39
40     // -------------------------------------------------------------- Properties
41

42
43     private UIData table = null;
44
45
46     /**
47      * <p>Return the <code>UIData</code> instance we are bound to.</p>
48      */

49     public UIData getTable() {
50
51         return (this.table);
52
53     }
54
55
56     /**
57      * <p>Set the <code>UIData</code> instance we are bound to.</p>
58      *
59      * @param table The <code>UIData</code> instance
60      */

61     public void setTable(UIData table) {
62
63         this.table = table;
64
65     }
66
67
68
69     // ----------------------------------------------------------------- Actions
70

71
72     /**
73      * <p>Create a new subscription.</p>
74      */

75     public String JavaDoc create() {
76
77         if (log.isDebugEnabled()) {
78             log.debug("create()");
79         }
80         FacesContext context = FacesContext.getCurrentInstance();
81         StringBuffer JavaDoc url = subscription(context);
82         url.append("?action=Create");
83         url.append("&username=");
84         User user = (User)
85             context.getExternalContext().getSessionMap().get("user");
86         url.append(user.getUsername());
87         forward(context, url.toString());
88         return (null);
89
90     }
91
92
93     /**
94      * <p>Delete an existing subscription.</p>
95      */

96     public String JavaDoc delete() {
97
98         if (log.isDebugEnabled()) {
99             log.debug("delete()");
100         }
101         FacesContext context = FacesContext.getCurrentInstance();
102         StringBuffer JavaDoc url = subscription(context);
103         url.append("?action=Delete");
104         url.append("&username=");
105         User user = (User)
106             context.getExternalContext().getSessionMap().get("user");
107         url.append(user.getUsername());
108         url.append("&host=");
109         Subscription subscription = (Subscription)
110             context.getExternalContext().getRequestMap().get("subscription");
111         url.append(subscription.getHost());
112         forward(context, url.toString());
113         return (null);
114
115     }
116
117
118     /**
119      * <p>Edit an existing subscription.</p>
120      */

121     public String JavaDoc edit() {
122
123         if (log.isDebugEnabled()) {
124             log.debug("edit()");
125         }
126         FacesContext context = FacesContext.getCurrentInstance();
127         StringBuffer JavaDoc url = subscription(context);
128         url.append("?action=Edit");
129         url.append("&username=");
130         User user = (User)
131             context.getExternalContext().getSessionMap().get("user");
132         url.append(user.getUsername());
133         url.append("&host=");
134         Subscription subscription = (Subscription)
135             context.getExternalContext().getRequestMap().get("subscription");
136         url.append(subscription.getHost());
137         forward(context, url.toString());
138         return (null);
139
140     }
141
142
143     /**
144      * <p>Update the subscriptions to reflect any revisions to the
145      * <code>type</code> and <code>autoConnect</code> properties.</p>
146      */

147     public String JavaDoc update() {
148
149         if (log.isDebugEnabled()) {
150             log.debug("update()");
151         }
152
153         FacesContext context = FacesContext.getCurrentInstance();
154
155         // Updates went directly to the underlying rows, so all we need to do
156
// is save the database
157
try {
158             UserDatabase database = (UserDatabase)
159                 context.getExternalContext().getApplicationMap().
160                 get(Constants.DATABASE_KEY);
161             database.save();
162         } catch (Exception JavaDoc e) {
163             log.error("Database save", e);
164         }
165
166         // Forward back to the edit registration page
167
StringBuffer JavaDoc sb = registration(context);
168         sb.append("?action=Edit");
169         forward(context, sb.toString());
170         return (null);
171
172     }
173
174
175 }
176
Popular Tags