1 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 30 31 public class RegistrationBacking extends AbstractBacking { 32 33 34 36 37 private static final Log log = LogFactory.getLog(RegistrationBacking.class); 38 39 40 42 43 private UIData table = null; 44 45 46 49 public UIData getTable() { 50 51 return (this.table); 52 53 } 54 55 56 61 public void setTable(UIData table) { 62 63 this.table = table; 64 65 } 66 67 68 69 71 72 75 public String create() { 76 77 if (log.isDebugEnabled()) { 78 log.debug("create()"); 79 } 80 FacesContext context = FacesContext.getCurrentInstance(); 81 StringBuffer 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 96 public String delete() { 97 98 if (log.isDebugEnabled()) { 99 log.debug("delete()"); 100 } 101 FacesContext context = FacesContext.getCurrentInstance(); 102 StringBuffer 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 121 public String edit() { 122 123 if (log.isDebugEnabled()) { 124 log.debug("edit()"); 125 } 126 FacesContext context = FacesContext.getCurrentInstance(); 127 StringBuffer 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 147 public String update() { 148 149 if (log.isDebugEnabled()) { 150 log.debug("update()"); 151 } 152 153 FacesContext context = FacesContext.getCurrentInstance(); 154 155 try { 158 UserDatabase database = (UserDatabase) 159 context.getExternalContext().getApplicationMap(). 160 get(Constants.DATABASE_KEY); 161 database.save(); 162 } catch (Exception e) { 163 log.error("Database save", e); 164 } 165 166 StringBuffer sb = registration(context); 168 sb.append("?action=Edit"); 169 forward(context, sb.toString()); 170 return (null); 171 172 } 173 174 175 } 176 | Popular Tags |