1 16 17 18 package org.apache.struts.webapp.example2; 19 20 21 import java.io.IOException ; 22 import javax.faces.FacesException; 23 import javax.faces.context.FacesContext; 24 25 26 29 30 public class RegistrationBacking { 31 32 33 35 36 public String getDeleteLabel() { return ("Delete"); } 40 public String getEditLabel() { return ("Edit"); } 41 42 43 45 46 49 public String create() { 50 51 FacesContext context = FacesContext.getCurrentInstance(); 52 StringBuffer url = base(context); 53 url.append("?action=Create"); 54 url.append("&username="); 55 User user = (User) 56 context.getExternalContext().getSessionMap().get("user"); 57 url.append(user.getUsername()); 58 forward(context, url.toString()); 59 return (null); 60 61 } 62 63 64 67 public String delete() { 68 69 FacesContext context = FacesContext.getCurrentInstance(); 70 StringBuffer url = base(context); 71 url.append("?action=Delete"); 72 url.append("&username="); 73 User user = (User) 74 context.getExternalContext().getSessionMap().get("user"); 75 url.append(user.getUsername()); 76 url.append("&host="); 77 Subscription subscription = (Subscription) 78 context.getExternalContext().getRequestMap().get("subscription"); 79 url.append(subscription.getHost()); 80 forward(context, url.toString()); 81 return (null); 82 83 } 84 85 86 89 public String edit() { 90 91 FacesContext context = FacesContext.getCurrentInstance(); 92 StringBuffer url = base(context); 93 url.append("?action=Edit"); 94 url.append("&username="); 95 User user = (User) 96 context.getExternalContext().getSessionMap().get("user"); 97 url.append(user.getUsername()); 98 url.append("&host="); 99 Subscription subscription = (Subscription) 100 context.getExternalContext().getRequestMap().get("subscription"); 101 url.append(subscription.getHost()); 102 forward(context, url.toString()); 103 return (null); 104 105 } 106 107 108 110 111 117 private StringBuffer base(FacesContext context) { 118 119 return (new StringBuffer ("/editSubscription.do")); 121 122 } 123 124 125 134 private void forward(FacesContext context, String url) { 135 136 try { 137 context.getExternalContext().dispatch(url); 138 } catch (IOException e) { 139 throw new FacesException(e); 140 } finally { 141 context.responseComplete(); 142 } 143 144 } 145 146 147 } 148 | Popular Tags |