1 package com.opensymphony.webwork.components; 2 3 import com.opensymphony.webwork.dispatcher.mapper.ActionMapperFactory; 4 import com.opensymphony.webwork.dispatcher.mapper.ActionMapping; 5 import com.opensymphony.webwork.views.jsp.TagUtils; 6 import com.opensymphony.webwork.views.util.UrlHelper; 7 import com.opensymphony.xwork.config.ConfigurationManager; 8 import com.opensymphony.xwork.config.entities.ActionConfig; 9 import com.opensymphony.xwork.util.OgnlValueStack; 10 11 import javax.servlet.http.HttpServletRequest ; 12 import javax.servlet.http.HttpServletResponse ; 13 14 20 public class Form extends ClosingUIBean { 21 final public static String OPEN_TEMPLATE = "form"; 22 final public static String TEMPLATE = "form-close"; 23 24 protected String action; 25 protected String target; 26 protected String enctype; 27 protected String method; 28 protected String namespace; 29 protected String validate; 30 31 public Form(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) { 32 super(stack, request, response); 33 } 34 35 protected boolean evaluateNameValue() { 36 return false; 37 } 38 39 public String getDefaultOpenTemplate() { 40 return OPEN_TEMPLATE; 41 } 42 43 protected String getDefaultTemplate() { 44 return TEMPLATE; 45 } 46 47 51 protected void evaluateExtraParams() { 52 super.evaluateExtraParams(); 53 54 String actionURL = com.opensymphony.webwork.portlet.context.PortletContext.getContext().getActionURL(); 56 boolean isPortlet = (actionURL != null && !"".equals(actionURL)); 57 59 if (action != null) { 60 61 String namespace; 63 64 if (this.namespace == null) { 65 namespace = TagUtils.buildNamespace(getStack(), request); 66 } else { 67 namespace = findString(this.namespace); 68 } 69 70 if (namespace == null) { 71 namespace = ""; 72 } 73 74 final ActionConfig actionConfig = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, action); 75 76 if (actionConfig != null) { 77 78 if (isPortlet) { 80 addParameter("action", actionURL); 81 addParameter("wwAction", action); 82 addParameter("isPortlet", "Portlet"); 83 } else { 85 String actionMethod = ""; 86 if (action.indexOf("!") != -1) { 87 int endIdx = action.lastIndexOf("!"); 88 actionMethod = action.substring(endIdx + 1, action.length()); 89 action = action.substring(0, endIdx); 90 } 91 92 ActionMapping mapping = new ActionMapping(action, namespace, actionMethod, parameters); 93 String result = UrlHelper.buildUrl(ActionMapperFactory.getMapper().getUriFromActionMapping(mapping), request, response, null); 94 addParameter("action", result); 95 } 96 97 98 addParameter("namespace", namespace); 99 100 if (name == null) { 102 addParameter("name", action); 103 } 104 105 if (id == null) { 107 addParameter("id", action); 108 } 109 } else if (action != null) { 110 String result = UrlHelper.buildUrl(action, request, response, null); 111 112 if (isPortlet) { 114 addParameter("action", actionURL); 115 addParameter("wwAction", action); 116 addParameter("isPortlet", "Portlet"); 117 } else { 119 addParameter("action", result); 120 } 121 122 int slash = result.lastIndexOf('/'); 124 if (slash != -1) { 125 addParameter("namespace", result.substring(0, slash)); 126 } else { 127 addParameter("namespace", ""); 128 } 129 130 if (id == null) { 132 slash = result.lastIndexOf('/'); 133 int dot = result.indexOf('.', slash); 134 if (dot != -1) { 135 id = result.substring(slash + 1, dot); 136 } else { 137 id = result.substring(slash + 1); 138 } 139 addParameter("id", id); 140 } 141 } 142 } 143 144 if (onsubmit != null) { 146 addParameter("onsubmit", findString(onsubmit)); 147 } 148 149 if (target != null) { 150 addParameter("target", findString(target)); 151 } 152 153 if (enctype != null) { 154 addParameter("enctype", findString(enctype)); 155 } 156 157 if (method != null) { 158 addParameter("method", findString(method)); 159 } 160 161 if (validate != null) { 162 addParameter("validate", findValue(validate, Boolean .class)); 163 } 164 } 165 166 String onsubmit; 168 169 public void setOnsubmit(String onsubmit) { 170 this.onsubmit = onsubmit; 171 } 172 174 public void setAction(String action) { 175 this.action = action; 176 } 177 178 public void setTarget(String target) { 179 this.target = target; 180 } 181 182 public void setEnctype(String enctype) { 183 this.enctype = enctype; 184 } 185 186 public void setMethod(String method) { 187 this.method = method; 188 } 189 190 public void setNamespace(String namespace) { 191 this.namespace = namespace; 192 } 193 194 public void setValidate(String validate) { 195 this.validate = validate; 196 } 197 198 199 } 200 | Popular Tags |