id resolution for <s:form> - minor cleanups

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@565756 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
René Gielen
2007-08-14 13:49:45 +00:00
parent 67de561c2a
commit 60227b13f0
3 changed files with 61 additions and 83 deletions
@@ -20,26 +20,6 @@
*/
package org.apache.struts2.components;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
//import org.apache.struts2.portlet.context.PortletActionContext;
//import org.apache.struts2.portlet.util.PortletUrlHelper;
import org.apache.struts2.views.util.UrlHelper;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.RuntimeConfiguration;
@@ -48,11 +28,18 @@ import com.opensymphony.xwork2.config.entities.InterceptorMapping;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptorUtil;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.validator.ActionValidatorManagerFactory;
import com.opensymphony.xwork2.validator.FieldValidator;
import com.opensymphony.xwork2.validator.ValidationInterceptor;
import com.opensymphony.xwork2.validator.Validator;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.Set;
/**
* <!-- START SNIPPET: javadoc -->
@@ -222,32 +209,30 @@ public class Form extends ClosingUIBean {
* </ol>
*/
protected void populateComponentHtmlId(Form form) {
boolean isAjax = "ajax".equalsIgnoreCase(this.theme);
String action = null;
if (this.action != null) {
// if it isn't specified, we'll make somethig up
action = findString(this.action);
}
if (id != null) {
addParameter("id", escape(id));
} else if (this.action != null) {
// if it isn't specified, we'll make somethig up
String action = findString(this.action);
if (action != null) {
addParameter("id", escape(action));
}
}
urlRenderer.renderFormUrl(this);
}
/**
* @param isAjax
* @param namespace
* @param action
* Evaluate client side JavaScript Enablement.
* @param actionName the actioName to check for
* @param namespace the namespace to check for
* @param actionMethod the method to ckeck for
*/
protected void evaluateClientSideJsEnablement(String actionName, String namespace, String actionMethod) {
// Only evaluate if Client-Side js is to be enable when validate=true
Boolean validate = (Boolean) getParameters().get("validate");
if (validate != null && validate.booleanValue()) {
if (validate != null && validate) {
addParameter("performValidation", Boolean.FALSE);
@@ -255,9 +240,8 @@ public class Form extends ClosingUIBean {
ActionConfig actionConfig = runtimeConfiguration.getActionConfig(namespace, actionName);
if (actionConfig != null) {
List interceptors = actionConfig.getInterceptors();
for (Iterator i = interceptors.iterator(); i.hasNext();) {
InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
List<InterceptorMapping> interceptors = actionConfig.getInterceptors();
for (InterceptorMapping interceptorMapping : interceptors) {
if (ValidationInterceptor.class.isInstance(interceptorMapping.getInterceptor())) {
ValidationInterceptor validationInterceptor = (ValidationInterceptor) interceptorMapping.getInterceptor();
@@ -280,10 +264,9 @@ public class Form extends ClosingUIBean {
return Collections.EMPTY_LIST;
}
List all = ActionValidatorManagerFactory.getInstance().getValidators(actionClass, (String) getParameters().get("actionName"));
List validators = new ArrayList();
for (Iterator iterator = all.iterator(); iterator.hasNext();) {
Validator validator = (Validator) iterator.next();
List<Validator> all = ActionValidatorManagerFactory.getInstance().getValidators(actionClass, (String) getParameters().get("actionName"));
List<Validator> validators = new ArrayList<Validator>();
for (Validator validator : all) {
if (validator instanceof FieldValidator) {
FieldValidator fieldValidator = (FieldValidator) validator;
if (fieldValidator.getFieldName().equals(name)) {
@@ -93,13 +93,11 @@ public class ServletUrlRenderer implements UrlRenderer {
public void renderFormUrl(Form formComponent) {
String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(),
formComponent.request);
String action = null;
String action;
if(formComponent.action != null) {
action = formComponent.findString(formComponent.action);
}
if (formComponent.action == null) {
} else {
// no action supplied? ok, then default to the current request
// (action or general URL)
ActionInvocation ai = (ActionInvocation) formComponent.getStack().getContext().get(
@@ -154,19 +152,19 @@ public class ServletUrlRenderer implements UrlRenderer {
}
// if the id isn't specified, use the action name
if (formComponent.getId() == null) {
formComponent.addParameter("id", action);
if (formComponent.getId() == null && action!=null ) {
formComponent.addParameter("id", formComponent.escape(action));
}
} else if (action != null) {
// Since we can't find an action alias in the configuration, we just
// assume the action attribute supplied is the path to be used as
// the URI this form is submitting to.
// Warn user that the specified namespace/action combo
// was not found in the configuration.
if (namespace != null) {
LOG.warn("No configuration found for the specified action: '" + action + "' in namespace: '" + namespace + "'. Form action defaulting to 'action' attribute's literal value.");
}
// Warn user that the specified namespace/action combo
// was not found in the configuration.
if (namespace != null) {
LOG.warn("No configuration found for the specified action: '" + action + "' in namespace: '" + namespace + "'. Form action defaulting to 'action' attribute's literal value.");
}
String result = UrlHelper.buildUrl(action, formComponent.request, formComponent.response, null);
formComponent.addParameter("action", result);
@@ -20,20 +20,17 @@
*/
package org.apache.struts2.components;
import com.opensymphony.xwork2.util.TextUtils;
import org.apache.struts2.StrutsException;
import org.apache.struts2.portlet.util.PortletUrlHelper;
import java.io.IOException;
import java.io.Writer;
import org.apache.struts2.StrutsException;
import org.apache.struts2.components.URL;
import org.apache.struts2.components.UrlRenderer;
import org.apache.struts2.portlet.util.PortletUrlHelper;
import com.opensymphony.xwork2.util.TextUtils;
/**
* Implementation of the {@link URLRenderer} interface that renders URLs for portlet environments.
* Implementation of the {@link UrlRenderer} interface that renders URLs for portlet environments.
*
* @see URLRenderer
* @see UrlRenderer
*
*/
public class PortletUrlRenderer implements UrlRenderer {
@@ -48,30 +45,30 @@ public class PortletUrlRenderer implements UrlRenderer {
scheme = urlComponent.scheme;
}
String result;
if (urlComponent.value == null && urlComponent.action != null) {
result = PortletUrlHelper.buildUrl(urlComponent.action, urlComponent.namespace, urlComponent.method, urlComponent.parameters, urlComponent.portletUrlType, urlComponent.portletMode, urlComponent.windowState);
} else {
result = PortletUrlHelper.buildResourceUrl(urlComponent.value, urlComponent.parameters);
}
if ( urlComponent.anchor != null && urlComponent.anchor.length() > 0 ) {
result += '#' + urlComponent.anchor;
}
String result;
if (urlComponent.value == null && urlComponent.action != null) {
result = PortletUrlHelper.buildUrl(urlComponent.action, urlComponent.namespace, urlComponent.method, urlComponent.parameters, urlComponent.portletUrlType, urlComponent.portletMode, urlComponent.windowState);
} else {
result = PortletUrlHelper.buildResourceUrl(urlComponent.value, urlComponent.parameters);
}
if ( urlComponent.anchor != null && urlComponent.anchor.length() > 0 ) {
result += '#' + urlComponent.anchor;
}
String var = urlComponent.getVar();
String var = urlComponent.getVar();
if (var != null) {
urlComponent.putInContext(result);
if (var != null) {
urlComponent.putInContext(result);
// add to the request and page scopes as well
urlComponent.req.setAttribute(var, result);
} else {
try {
writer.write(result);
} catch (IOException e) {
throw new StrutsException("IOError: " + e.getMessage(), e);
}
}
// add to the request and page scopes as well
urlComponent.req.setAttribute(var, result);
} else {
try {
writer.write(result);
} catch (IOException e) {
throw new StrutsException("IOError: " + e.getMessage(), e);
}
}
}
/**