001: /*
002: * $Id: RegistrationBacking.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.webapp.example;
023:
024: import javax.faces.component.UIData;
025: import javax.faces.context.FacesContext;
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028:
029: /**
030: * <p>Backing bean for the <code>registration.jsp</code> page.</p>
031: */
032:
033: public class RegistrationBacking extends AbstractBacking {
034:
035: // -------------------------------------------------------- Static Variables
036:
037: private static final Log log = LogFactory
038: .getLog(RegistrationBacking.class);
039:
040: // -------------------------------------------------------------- Properties
041:
042: private UIData table = null;
043:
044: /**
045: * <p>Return the <code>UIData</code> instance we are bound to.</p>
046: */
047: public UIData getTable() {
048:
049: return (this .table);
050:
051: }
052:
053: /**
054: * <p>Set the <code>UIData</code> instance we are bound to.</p>
055: *
056: * @param table The <code>UIData</code> instance
057: */
058: public void setTable(UIData table) {
059:
060: this .table = table;
061:
062: }
063:
064: // ----------------------------------------------------------------- Actions
065:
066: /**
067: * <p>Create a new subscription.</p>
068: */
069: public String create() {
070:
071: if (log.isDebugEnabled()) {
072: log.debug("create()");
073: }
074: FacesContext context = FacesContext.getCurrentInstance();
075: StringBuffer url = subscription(context);
076: url.append("?action=Create");
077: url.append("&username=");
078: User user = (User) context.getExternalContext().getSessionMap()
079: .get("user");
080: url.append(user.getUsername());
081: forward(context, url.toString());
082: return (null);
083:
084: }
085:
086: /**
087: * <p>Delete an existing subscription.</p>
088: */
089: public String delete() {
090:
091: if (log.isDebugEnabled()) {
092: log.debug("delete()");
093: }
094: FacesContext context = FacesContext.getCurrentInstance();
095: StringBuffer url = subscription(context);
096: url.append("?action=Delete");
097: url.append("&username=");
098: User user = (User) context.getExternalContext().getSessionMap()
099: .get("user");
100: url.append(user.getUsername());
101: url.append("&host=");
102: Subscription subscription = (Subscription) context
103: .getExternalContext().getRequestMap().get(
104: "subscription");
105: url.append(subscription.getHost());
106: forward(context, url.toString());
107: return (null);
108:
109: }
110:
111: /**
112: * <p>Edit an existing subscription.</p>
113: */
114: public String edit() {
115:
116: if (log.isDebugEnabled()) {
117: log.debug("edit()");
118: }
119: FacesContext context = FacesContext.getCurrentInstance();
120: StringBuffer url = subscription(context);
121: url.append("?action=Edit");
122: url.append("&username=");
123: User user = (User) context.getExternalContext().getSessionMap()
124: .get("user");
125: url.append(user.getUsername());
126: url.append("&host=");
127: Subscription subscription = (Subscription) context
128: .getExternalContext().getRequestMap().get(
129: "subscription");
130: url.append(subscription.getHost());
131: forward(context, url.toString());
132: return (null);
133:
134: }
135:
136: /**
137: * <p>Update the subscriptions to reflect any revisions to the
138: * <code>type</code> and <code>autoConnect</code> properties.</p>
139: */
140: public String update() {
141:
142: if (log.isDebugEnabled()) {
143: log.debug("update()");
144: }
145:
146: FacesContext context = FacesContext.getCurrentInstance();
147:
148: // Updates went directly to the underlying rows, so all we need to do
149: // is save the database
150: try {
151: UserDatabase database = (UserDatabase) context
152: .getExternalContext().getApplicationMap().get(
153: Constants.DATABASE_KEY);
154: database.save();
155: } catch (Exception e) {
156: log.error("Database save", e);
157: }
158:
159: // Forward back to the edit registration page
160: StringBuffer sb = registration(context);
161: sb.append("?action=Edit");
162: forward(context, sb.toString());
163: return (null);
164:
165: }
166:
167: }
|