mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
WW-4252 Uses TagUtils instead directly calling Dispatcher.getInstance()
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1549067 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -442,14 +442,11 @@ public class Dispatcher {
|
||||
}
|
||||
|
||||
private Container init_PreloadConfiguration() {
|
||||
Configuration config = configurationManager.getConfiguration();
|
||||
Container container = config.getContainer();
|
||||
Container container = getContainer();
|
||||
|
||||
boolean reloadi18n = Boolean.valueOf(container.getInstance(String.class, StrutsConstants.STRUTS_I18N_RELOAD));
|
||||
LocalizedTextUtil.setReloadBundles(reloadi18n);
|
||||
|
||||
ContainerHolder.store(container);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
@@ -548,8 +545,7 @@ public class Dispatcher {
|
||||
String name = mapping.getName();
|
||||
String method = mapping.getMethod();
|
||||
|
||||
Configuration config = configurationManager.getConfiguration();
|
||||
ActionProxy proxy = config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
|
||||
ActionProxy proxy = getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
|
||||
namespace, name, method, extraContext, true, false);
|
||||
|
||||
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation().getStack());
|
||||
@@ -664,7 +660,6 @@ public class Dispatcher {
|
||||
}
|
||||
|
||||
extraContext.put(ActionContext.LOCALE, locale);
|
||||
//extraContext.put(ActionContext.DEV_MODE, Boolean.valueOf(devMode));
|
||||
|
||||
extraContext.put(StrutsStatics.HTTP_REQUEST, request);
|
||||
extraContext.put(StrutsStatics.HTTP_RESPONSE, response);
|
||||
|
||||
@@ -24,6 +24,7 @@ package org.apache.struts2.util;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
@@ -53,10 +54,11 @@ public class StrutsTestCaseHelper {
|
||||
Dispatcher du = new Dispatcher(ctx, params);
|
||||
du.init();
|
||||
Dispatcher.setInstance(du);
|
||||
|
||||
|
||||
// Reset the value stack
|
||||
ValueStack stack = du.getContainer().getInstance(ValueStackFactory.class).createValueStack();
|
||||
stack.getContext().put(ActionContext.CONTAINER, du.getContainer());
|
||||
Container container = du.getContainer();
|
||||
ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
stack.getContext().put(ActionContext.CONTAINER, container);
|
||||
ActionContext.setContext(new ActionContext(stack.getContext()));
|
||||
|
||||
return du;
|
||||
|
||||
@@ -25,8 +25,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import org.apache.struts2.components.Component;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
@@ -45,8 +45,9 @@ public abstract class ComponentTagSupport extends StrutsBodyTagSupport {
|
||||
}
|
||||
|
||||
public int doStartTag() throws JspException {
|
||||
component = getBean(getStack(), (HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
|
||||
Container container = Dispatcher.getInstance().getContainer();
|
||||
ValueStack stack = getStack();
|
||||
component = getBean(stack, (HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
|
||||
Container container = (Container) stack.getContext().get(ActionContext.CONTAINER);
|
||||
container.inject(component);
|
||||
|
||||
populateParams();
|
||||
|
||||
@@ -13,11 +13,10 @@ public class ClassInstantiationTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testCompositeActionMapperInstantiationWithList() throws Exception {
|
||||
// given
|
||||
Dispatcher du = initDispatcher(new HashMap<String, String>() {{
|
||||
initDispatcher(new HashMap<String, String>() {{
|
||||
put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
|
||||
put(StrutsConstants.STRUTS_MAPPER_COMPOSITE, "struts,restful");
|
||||
}});
|
||||
Container container = du.getContainer();
|
||||
|
||||
// when
|
||||
ActionMapper instance = container.getInstance(ActionMapper.class, "composite");
|
||||
@@ -28,10 +27,9 @@ public class ClassInstantiationTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testCompositeActionMapperInstantiationWithoutList() throws Exception {
|
||||
// given
|
||||
Dispatcher du = initDispatcher(new HashMap<String, String>() {{
|
||||
initDispatcher(new HashMap<String, String>() {{
|
||||
put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
|
||||
}});
|
||||
Container container = du.getContainer();
|
||||
|
||||
// when
|
||||
try {
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
|
||||
package org.apache.struts2;
|
||||
|
||||
import com.opensymphony.xwork2.ActionProxyFactory;
|
||||
import com.opensymphony.xwork2.XWorkTestCase;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
@@ -71,7 +74,9 @@ public abstract class StrutsInternalTestCase extends XWorkTestCase {
|
||||
logger.setLevel(Level.WARNING);
|
||||
LoggerFactory.setLoggerFactory(new JdkLoggerFactory());
|
||||
}
|
||||
|
||||
|
||||
protected Dispatcher dispatcher;
|
||||
|
||||
/**
|
||||
* Sets up the configuration settings, XWork configuration, and
|
||||
* message resources
|
||||
@@ -82,11 +87,12 @@ public abstract class StrutsInternalTestCase extends XWorkTestCase {
|
||||
}
|
||||
|
||||
protected Dispatcher initDispatcher(Map<String,String> params) {
|
||||
Dispatcher du = StrutsTestCaseHelper.initDispatcher(new MockServletContext(), params);
|
||||
configurationManager = du.getConfigurationManager();
|
||||
dispatcher = StrutsTestCaseHelper.initDispatcher(new MockServletContext(), params);
|
||||
configurationManager = dispatcher.getConfigurationManager();
|
||||
configuration = configurationManager.getConfiguration();
|
||||
container = configuration.getContainer();
|
||||
return du;
|
||||
container.inject(dispatcher);
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,6 +110,11 @@ public abstract class StrutsInternalTestCase extends XWorkTestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
// maybe someone else already destroyed Dispatcher
|
||||
if (dispatcher != null && dispatcher.getConfigurationManager() != null) {
|
||||
dispatcher.cleanup();
|
||||
dispatcher = null;
|
||||
}
|
||||
StrutsTestCaseHelper.tearDown();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,18 +21,7 @@
|
||||
|
||||
package org.apache.struts2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.struts2.dispatcher.ServletDispatcherResult;
|
||||
import org.apache.struts2.interceptor.TokenInterceptor;
|
||||
import org.apache.struts2.interceptor.TokenSessionStoreInterceptor;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionChainResult;
|
||||
import com.opensymphony.xwork2.ActionProxyFactory;
|
||||
import com.opensymphony.xwork2.DefaultActionProxyFactory;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
@@ -47,6 +36,13 @@ import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.interceptor.ParametersInterceptor;
|
||||
import com.opensymphony.xwork2.mock.MockResult;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import com.opensymphony.xwork2.validator.ValidationInterceptor;
|
||||
import org.apache.struts2.dispatcher.ServletDispatcherResult;
|
||||
import org.apache.struts2.interceptor.TokenInterceptor;
|
||||
import org.apache.struts2.interceptor.TokenSessionStoreInterceptor;
|
||||
import org.apache.struts2.views.jsp.ui.DoubleValidationAction;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
@@ -89,6 +85,15 @@ public class TestConfigurationProvider implements ConfigurationProvider {
|
||||
.build())
|
||||
.build();
|
||||
|
||||
ValidationInterceptor validationInterceptor = new ValidationInterceptor();
|
||||
validationInterceptor.setIncludeMethods("*");
|
||||
|
||||
ActionConfig doubleValidationActionConfig = new ActionConfig.Builder("", "doubleValidationAction", DoubleValidationAction.class.getName())
|
||||
.addResultConfig(new ResultConfig.Builder(Action.SUCCESS, ServletDispatcherResult.class.getName())
|
||||
.addParam("location", "success.jsp")
|
||||
.build())
|
||||
.addInterceptor(new InterceptorMapping("validation", validationInterceptor))
|
||||
.build();
|
||||
|
||||
ActionConfig testActionConfig = new ActionConfig.Builder("", "", TestAction.class.getName())
|
||||
.addResultConfig(new ResultConfig.Builder(Action.SUCCESS, ServletDispatcherResult.class.getName())
|
||||
@@ -97,7 +102,6 @@ public class TestConfigurationProvider implements ConfigurationProvider {
|
||||
.addInterceptor(new InterceptorMapping("params", new ParametersInterceptor()))
|
||||
.build();
|
||||
|
||||
|
||||
ActionConfig tokenActionConfig = new ActionConfig.Builder("", "", TestAction.class.getName())
|
||||
.addInterceptor(new InterceptorMapping("token", new TokenInterceptor()))
|
||||
.addResultConfig(new ResultConfig.Builder("invalid.token", MockResult.class.getName()).build())
|
||||
@@ -115,6 +119,7 @@ public class TestConfigurationProvider implements ConfigurationProvider {
|
||||
PackageConfig defaultPackageConfig = new PackageConfig.Builder("")
|
||||
.addActionConfig(EXECUTION_COUNT_ACTION_NAME, executionCountActionConfig)
|
||||
.addActionConfig(TEST_ACTION_NAME, testActionConfig)
|
||||
.addActionConfig("doubleValidationAction", doubleValidationActionConfig)
|
||||
.addActionConfig(TOKEN_ACTION_NAME, tokenActionConfig)
|
||||
.addActionConfig(TOKEN_SESSION_ACTION_NAME, tokenSessionActionConfig)
|
||||
.addActionConfig("testActionTagAction", new ActionConfig.Builder("", "", TestAction.class.getName())
|
||||
@@ -132,6 +137,15 @@ public class TestConfigurationProvider implements ConfigurationProvider {
|
||||
.build();
|
||||
|
||||
configuration.addPackageConfig("namespacePackage", namespacePackageConfig);
|
||||
|
||||
PackageConfig testActionWithNamespacePackageConfig = new PackageConfig.Builder("testActionNamespacePackages")
|
||||
.namespace(TEST_NAMESPACE)
|
||||
.addParent(defaultPackageConfig)
|
||||
.addActionConfig(TEST_ACTION_NAME, new ActionConfig.Builder("", "", TestAction.class.getName()).build())
|
||||
.build();
|
||||
|
||||
configuration.addPackageConfig("testActionNamespacePackages", testActionWithNamespacePackageConfig);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -172,7 +172,7 @@ public class DispatcherTest extends StrutsInternalTestCase {
|
||||
assertTrue(state.isInitialized);
|
||||
|
||||
du.cleanup();
|
||||
|
||||
|
||||
assertTrue(state.isDestroyed);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,6 @@ public class PlainTextResultTest extends StrutsInternalTestCase {
|
||||
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
stack = null;
|
||||
invocation = null;
|
||||
context = null;
|
||||
|
||||
@@ -81,9 +81,7 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
|
||||
|
||||
|
||||
request.setRequestURI("/tutorial/test2.action");
|
||||
Dispatcher dispatcher = Dispatcher.getInstance();
|
||||
ActionMapping mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(
|
||||
request, dispatcher.getConfigurationManager());
|
||||
ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
|
||||
dispatcher.serviceAction(request, response, servletContext, mapping);
|
||||
assertEquals("beforenestedafter", stringWriter.toString());
|
||||
}
|
||||
@@ -107,9 +105,7 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
|
||||
|
||||
|
||||
request.setRequestURI("/tutorial/test5.action");
|
||||
Dispatcher dispatcher = Dispatcher.getInstance();
|
||||
ActionMapping mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(
|
||||
request, dispatcher.getConfigurationManager());
|
||||
ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
|
||||
dispatcher.serviceAction(request, response, servletContext, mapping);
|
||||
assertEquals("beforenestedafter", stringWriter.toString());
|
||||
}
|
||||
@@ -218,8 +214,7 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
|
||||
|
||||
|
||||
request.setRequestURI("/tutorial/test6.action");
|
||||
Dispatcher dispatcher = Dispatcher.getInstance();
|
||||
ActionMapping mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request, dispatcher.getConfigurationManager());
|
||||
ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
|
||||
dispatcher.serviceAction(request, response, servletContext, mapping);
|
||||
|
||||
// TODO lukaszlenart: remove expectedJDK15 and if() after switching to Java 1.6
|
||||
@@ -279,8 +274,7 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
|
||||
|
||||
|
||||
request.setRequestURI("/tutorial/test7.action");
|
||||
Dispatcher dispatcher = Dispatcher.getInstance();
|
||||
ActionMapping mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request, dispatcher.getConfigurationManager());
|
||||
ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
|
||||
dispatcher.serviceAction(request, response, servletContext, mapping);
|
||||
String expected = "<input type=\"radio\" name=\"client\" id=\"client_foo\" value=\"foo\"/><label for=\"client_foo\">foo</label>\n"
|
||||
+ "<input type=\"radio\" name=\"client\" id=\"client_bar\" value=\"bar\"/><label for=\"client_bar\">bar</label>\n"
|
||||
@@ -310,8 +304,7 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
|
||||
ServletActionContext.setServletContext(servletContext);
|
||||
|
||||
request.setRequestURI("/tutorial/test8.action");
|
||||
Dispatcher dispatcher = Dispatcher.getInstance();
|
||||
ActionMapping mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request, dispatcher.getConfigurationManager());
|
||||
ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
|
||||
dispatcher.serviceAction(request, response, servletContext, mapping);
|
||||
String expected = "<input type=\"text\"autofocus=\"autofocus\"/>";
|
||||
assertEquals(expected, stringWriter.toString());
|
||||
@@ -321,12 +314,15 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
|
||||
super.setUp();
|
||||
mgr = new FreemarkerManager();
|
||||
mgr.setEncoding("UTF-8");
|
||||
|
||||
DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
|
||||
container.inject(factory);
|
||||
mgr.setFileManagerFactory(factory);
|
||||
|
||||
FreemarkerThemeTemplateLoader themeLoader = new FreemarkerThemeTemplateLoader();
|
||||
container.inject(themeLoader);
|
||||
mgr.setThemeTemplateLoader(themeLoader);
|
||||
|
||||
stringWriter = new StringWriter();
|
||||
writer = new PrintWriter(stringWriter);
|
||||
response = new StrutsMockHttpServletResponse();
|
||||
@@ -334,14 +330,17 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
|
||||
request = new MockHttpServletRequest();
|
||||
servletContext = new StrutsMockServletContext();
|
||||
stack = ActionContext.getContext().getValueStack();
|
||||
|
||||
context = new ActionContext(stack.getContext());
|
||||
context.put(StrutsStatics.HTTP_RESPONSE, response);
|
||||
context.put(StrutsStatics.HTTP_REQUEST, request);
|
||||
context.put(StrutsStatics.SERVLET_CONTEXT, servletContext);
|
||||
|
||||
ServletActionContext.setServletContext(servletContext);
|
||||
ServletActionContext.setRequest(request);
|
||||
ServletActionContext.setResponse(response);
|
||||
servletContext.setAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY, null);
|
||||
|
||||
invocation = new MockActionInvocation();
|
||||
invocation.setStack(stack);
|
||||
invocation.setInvocationContext(context);
|
||||
@@ -360,4 +359,5 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,10 +77,13 @@ public abstract class AbstractTagTest extends StrutsInternalTestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
/**
|
||||
* create our standard mock objects
|
||||
*/
|
||||
createMocks();
|
||||
}
|
||||
|
||||
protected void createMocks() {
|
||||
action = this.getAction();
|
||||
stack = ActionContext.getContext().getValueStack();
|
||||
context = stack.getContext();
|
||||
|
||||
@@ -300,12 +300,8 @@ public class ActionTagTest extends AbstractTagTest {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
initDispatcher(new HashMap() {{ put("configProviders", TestConfigurationProvider.class.getName()); }});
|
||||
|
||||
ActionContext actionContext = new ActionContext(context);
|
||||
actionContext.setValueStack(stack);
|
||||
ActionContext.setContext(actionContext);
|
||||
initDispatcher(new HashMap<String, String>() {{ put("configProviders", TestConfigurationProvider.class.getName()); }});
|
||||
createMocks();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
@@ -21,12 +21,7 @@
|
||||
|
||||
package org.apache.struts2.views.jsp.ui;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.RuntimeConfiguration;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
@@ -89,7 +84,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
}
|
||||
|
||||
public void testFormWithContext() throws Exception {
|
||||
request.setupGetContext("/somecontext");
|
||||
request.setupGetContext("/testNamespace");
|
||||
|
||||
FormTag tag = new FormTag();
|
||||
tag.setTheme("xhtml");
|
||||
@@ -205,63 +200,13 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
*/
|
||||
public void testFormWithCustomOnsubmitEnabledWithValidateEnabled1() throws Exception {
|
||||
|
||||
final Container cont = container;
|
||||
// used to determined if the form action needs js validation
|
||||
configurationManager.setConfiguration(new com.opensymphony.xwork2.config.impl.DefaultConfiguration() {
|
||||
private DefaultConfiguration self = this;
|
||||
public Container getContainer() {
|
||||
return new Container() {
|
||||
public <T> T inject(Class<T> implementation) {return null;}
|
||||
public void removeScopeStrategy() {}
|
||||
public void setScopeStrategy(Strategy scopeStrategy) {}
|
||||
public <T> T getInstance(Class<T> type, String name) {return null;}
|
||||
public <T> T getInstance(Class<T> type) {return cont.getInstance(type);}
|
||||
public Set<String> getInstanceNames(Class<?> type) {return null;}
|
||||
|
||||
public void inject(Object o) {
|
||||
cont.inject(o);
|
||||
if (o instanceof Form) {
|
||||
((Form)o).setConfiguration(self);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
public RuntimeConfiguration getRuntimeConfiguration() {
|
||||
return new RuntimeConfiguration() {
|
||||
public ActionConfig getActionConfig(String namespace, String name) {
|
||||
ActionConfig actionConfig = new ActionConfig("", name, "") {
|
||||
public List getInterceptors() {
|
||||
List interceptors = new ArrayList();
|
||||
|
||||
ValidationInterceptor validationInterceptor = new ValidationInterceptor();
|
||||
validationInterceptor.setIncludeMethods("*");
|
||||
|
||||
InterceptorMapping interceptorMapping = new InterceptorMapping("validation", validationInterceptor);
|
||||
interceptors.add(interceptorMapping);
|
||||
|
||||
return interceptors;
|
||||
}
|
||||
public String getClassName() {
|
||||
return ActionSupport.class.getName();
|
||||
}
|
||||
};
|
||||
return actionConfig;
|
||||
}
|
||||
|
||||
public Map getActionConfigs() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Dispatcher.getInstance().setConfigurationManager(configurationManager);
|
||||
prepareMockInvocation();
|
||||
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setName("myForm");
|
||||
tag.setMethod("post");
|
||||
tag.setAction("myAction");
|
||||
tag.setAction("doubleValidationAction");
|
||||
tag.setAcceptcharset("UTF-8");
|
||||
tag.setEnctype("myEncType");
|
||||
tag.setTitle("mytitle");
|
||||
@@ -289,90 +234,31 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
* "excludes" all methods.
|
||||
*/
|
||||
public void testFormWithCustomOnsubmitEnabledWithValidateEnabled2() throws Exception {
|
||||
prepareMockInvocation();
|
||||
|
||||
com.opensymphony.xwork2.config.Configuration originalConfiguration = configurationManager.getConfiguration();
|
||||
ObjectFactory originalObjectFactory = ObjectFactory.getObjectFactory();
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setName("myForm");
|
||||
tag.setMethod("post");
|
||||
tag.setAction("testAction");
|
||||
tag.setAcceptcharset("UTF-8");
|
||||
tag.setEnctype("myEncType");
|
||||
tag.setTitle("mytitle");
|
||||
tag.setOnsubmit("submitMe()");
|
||||
tag.setValidate("true");
|
||||
tag.setNamespace("");
|
||||
|
||||
final Container cont = container;
|
||||
try {
|
||||
// used to determined if the form action needs js validation
|
||||
configurationManager.setConfiguration(new DefaultConfiguration() {
|
||||
private DefaultConfiguration self = this;
|
||||
public Container getContainer() {
|
||||
return new Container() {
|
||||
public <T> T inject(Class<T> implementation) {return null;}
|
||||
public void removeScopeStrategy() {}
|
||||
public void setScopeStrategy(Strategy scopeStrategy) {}
|
||||
public <T> T getInstance(Class<T> type, String name) {return null;}
|
||||
public <T> T getInstance(Class<T> type) {return cont.getInstance(type);}
|
||||
public Set<String> getInstanceNames(Class<?> type) {return null;}
|
||||
UpDownSelectTag t = new UpDownSelectTag();
|
||||
t.setPageContext(pageContext);
|
||||
t.setName("myUpDownSelectTag");
|
||||
t.setList("{}");
|
||||
|
||||
public void inject(Object o) {
|
||||
cont.inject(o);
|
||||
if (o instanceof Form) {
|
||||
((Form)o).setConfiguration(self);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
public RuntimeConfiguration getRuntimeConfiguration() {
|
||||
return new RuntimeConfiguration() {
|
||||
public ActionConfig getActionConfig(String namespace, String name) {
|
||||
ActionConfig actionConfig = new ActionConfig("", name, "") {
|
||||
public List getInterceptors() {
|
||||
List interceptors = new ArrayList();
|
||||
tag.doStartTag();
|
||||
t.doStartTag();
|
||||
t.doEndTag();
|
||||
tag.doEndTag();
|
||||
|
||||
ValidationInterceptor validationInterceptor = new ValidationInterceptor();
|
||||
validationInterceptor.setExcludeMethods("*");
|
||||
|
||||
InterceptorMapping interceptorMapping = new InterceptorMapping("validation", validationInterceptor);
|
||||
interceptors.add(interceptorMapping);
|
||||
|
||||
return interceptors;
|
||||
}
|
||||
public String getClassName() {
|
||||
return ActionSupport.class.getName();
|
||||
}
|
||||
};
|
||||
return actionConfig;
|
||||
}
|
||||
|
||||
public Map getActionConfigs() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Dispatcher.getInstance().setConfigurationManager(configurationManager);
|
||||
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setName("myForm");
|
||||
tag.setMethod("post");
|
||||
tag.setAction("myAction");
|
||||
tag.setAcceptcharset("UTF-8");
|
||||
tag.setEnctype("myEncType");
|
||||
tag.setTitle("mytitle");
|
||||
tag.setOnsubmit("submitMe()");
|
||||
tag.setValidate("true");
|
||||
tag.setNamespace("");
|
||||
|
||||
UpDownSelectTag t = new UpDownSelectTag();
|
||||
t.setPageContext(pageContext);
|
||||
t.setName("myUpDownSelectTag");
|
||||
t.setList("{}");
|
||||
|
||||
tag.doStartTag();
|
||||
t.doStartTag();
|
||||
t.doEndTag();
|
||||
tag.doEndTag();
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-11.txt"));
|
||||
}
|
||||
finally {
|
||||
configurationManager.setConfiguration(originalConfiguration);
|
||||
}
|
||||
verify(FormTag.class.getResource("Formtag-11.txt"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,63 +266,12 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
*/
|
||||
public void testFormWithCustomOnsubmitEnabledWithValidateEnabled3() throws Exception {
|
||||
|
||||
final Container cont = container;
|
||||
// used to determined if the form action needs js validation
|
||||
configurationManager.setConfiguration(new com.opensymphony.xwork2.config.impl.DefaultConfiguration() {
|
||||
private DefaultConfiguration self = this;
|
||||
public Container getContainer() {
|
||||
return new Container() {
|
||||
public <T> T inject(Class<T> implementation) {return null;}
|
||||
public void removeScopeStrategy() {}
|
||||
public void setScopeStrategy(Strategy scopeStrategy) {}
|
||||
public <T> T getInstance(Class<T> type, String name) {return null;}
|
||||
public <T> T getInstance(Class<T> type) {return cont.getInstance(type);}
|
||||
public Set<String> getInstanceNames(Class<?> type) {return null;}
|
||||
|
||||
public void inject(Object o) {
|
||||
cont.inject(o);
|
||||
if (o instanceof Form) {
|
||||
((Form)o).setConfiguration(self);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
public RuntimeConfiguration getRuntimeConfiguration() {
|
||||
return new RuntimeConfiguration() {
|
||||
public ActionConfig getActionConfig(String namespace, String name) {
|
||||
ActionConfig actionConfig = new ActionConfig("", name, IntValidationAction.class.getName()) {
|
||||
public List getInterceptors() {
|
||||
List interceptors = new ArrayList();
|
||||
|
||||
ValidationInterceptor validationInterceptor = new ValidationInterceptor();
|
||||
validationInterceptor.setIncludeMethods("*");
|
||||
|
||||
InterceptorMapping interceptorMapping = new InterceptorMapping("validation", validationInterceptor);
|
||||
interceptors.add(interceptorMapping);
|
||||
|
||||
return interceptors;
|
||||
}
|
||||
public String getClassName() {
|
||||
return IntValidationAction.class.getName();
|
||||
}
|
||||
};
|
||||
return actionConfig;
|
||||
}
|
||||
|
||||
public Map getActionConfigs() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Dispatcher.getInstance().setConfigurationManager(configurationManager);
|
||||
|
||||
prepareMockInvocation();
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setName("myForm");
|
||||
tag.setMethod("post");
|
||||
tag.setAction("myAction");
|
||||
tag.setAction("doubleValidationAction");
|
||||
tag.setAcceptcharset("UTF-8");
|
||||
tag.setEnctype("myEncType");
|
||||
tag.setTitle("mytitle");
|
||||
@@ -462,64 +297,13 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
* Tests the numbers are formatted correctly to not break the javascript, using doubles
|
||||
*/
|
||||
public void testFormWithCustomOnsubmitEnabledWithValidateEnabled4() throws Exception {
|
||||
|
||||
final Container cont = container;
|
||||
// used to determined if the form action needs js validation
|
||||
configurationManager.setConfiguration(new com.opensymphony.xwork2.config.impl.DefaultConfiguration() {
|
||||
private DefaultConfiguration self = this;
|
||||
public Container getContainer() {
|
||||
return new Container() {
|
||||
public <T> T inject(Class<T> implementation) {return null;}
|
||||
public void removeScopeStrategy() {}
|
||||
public void setScopeStrategy(Strategy scopeStrategy) {}
|
||||
public <T> T getInstance(Class<T> type, String name) {return null;}
|
||||
public <T> T getInstance(Class<T> type) {return cont.getInstance(type);}
|
||||
public Set<String> getInstanceNames(Class<?> type) {return null;}
|
||||
|
||||
public void inject(Object o) {
|
||||
cont.inject(o);
|
||||
if (o instanceof Form) {
|
||||
((Form)o).setConfiguration(self);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
public RuntimeConfiguration getRuntimeConfiguration() {
|
||||
return new RuntimeConfiguration() {
|
||||
public ActionConfig getActionConfig(String namespace, String name) {
|
||||
ActionConfig actionConfig = new ActionConfig("", name, DoubleValidationAction.class.getName()) {
|
||||
public List getInterceptors() {
|
||||
List interceptors = new ArrayList();
|
||||
|
||||
ValidationInterceptor validationInterceptor = new ValidationInterceptor();
|
||||
validationInterceptor.setIncludeMethods("*");
|
||||
|
||||
InterceptorMapping interceptorMapping = new InterceptorMapping("validation", validationInterceptor);
|
||||
interceptors.add(interceptorMapping);
|
||||
|
||||
return interceptors;
|
||||
}
|
||||
public String getClassName() {
|
||||
return DoubleValidationAction.class.getName();
|
||||
}
|
||||
};
|
||||
return actionConfig;
|
||||
}
|
||||
|
||||
public Map getActionConfigs() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Dispatcher.getInstance().setConfigurationManager(configurationManager);
|
||||
prepareMockInvocation();
|
||||
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setName("myForm");
|
||||
tag.setMethod("post");
|
||||
tag.setAction("myAction");
|
||||
tag.setAction("doubleValidationAction");
|
||||
tag.setAcceptcharset("UTF-8");
|
||||
tag.setEnctype("myEncType");
|
||||
tag.setTitle("mytitle");
|
||||
@@ -541,6 +325,24 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
verify(FormTag.class.getResource("Formtag-24.txt"));
|
||||
}
|
||||
|
||||
private void prepareMockInvocation() throws Exception {
|
||||
ActionContext.getContext().setValueStack(stack);
|
||||
|
||||
ActionConfig config = new ActionConfig.Builder("", "name", "").build();
|
||||
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
|
||||
ActionProxy proxy = EasyMock.createNiceMock(ActionProxy.class);
|
||||
|
||||
EasyMock.expect(invocation.getProxy()).andReturn(proxy).anyTimes();
|
||||
EasyMock.expect(invocation.getAction()).andReturn(null).anyTimes();
|
||||
EasyMock.expect(invocation.invoke()).andReturn(Action.SUCCESS).anyTimes();
|
||||
EasyMock.expect(proxy.getMethod()).andReturn("execute").anyTimes();
|
||||
EasyMock.expect(proxy.getConfig()).andReturn(config).anyTimes();
|
||||
|
||||
EasyMock.replay(invocation);
|
||||
EasyMock.replay(proxy);
|
||||
|
||||
ActionContext.getContext().setActionInvocation(invocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test with form tag validation disabled.
|
||||
@@ -582,6 +384,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
put(StrutsConstants.STRUTS_ACTION_EXTENSION, "jspa");
|
||||
put("configProviders", TestConfigurationProvider.class.getName());
|
||||
}});
|
||||
createMocks();
|
||||
request.setupGetServletPath("/testNamespace/testNamespaceAction");
|
||||
|
||||
FormTag tag = new FormTag();
|
||||
@@ -637,7 +440,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
}
|
||||
|
||||
public void testFormTagForStackOverflowException1() throws Exception {
|
||||
request.setRequestURI("/requestUri");
|
||||
request.setRequestURI("/testAction");
|
||||
|
||||
FormTag form1 = new FormTag();
|
||||
form1.setPageContext(pageContext);
|
||||
@@ -804,25 +607,9 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
initDispatcher(new HashMap<String,String>(){{
|
||||
initDispatcher(new HashMap<String, String>() {{
|
||||
put("configProviders", TestConfigurationProvider.class.getName());
|
||||
}});
|
||||
ActionContext.getContext().setValueStack(stack);
|
||||
|
||||
ActionConfig config = new ActionConfig.Builder("", "name", "").build();
|
||||
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
|
||||
ActionProxy proxy = EasyMock.createNiceMock(ActionProxy.class);
|
||||
|
||||
EasyMock.expect(invocation.getProxy()).andReturn(proxy).anyTimes();
|
||||
EasyMock.expect(invocation.getAction()).andReturn(null).anyTimes();
|
||||
EasyMock.expect(invocation.invoke()).andReturn(Action.SUCCESS).anyTimes();
|
||||
EasyMock.expect(proxy.getMethod()).andReturn("execute").anyTimes();
|
||||
EasyMock.expect(proxy.getConfig()).andReturn(config).anyTimes();
|
||||
|
||||
|
||||
EasyMock.replay(invocation);
|
||||
EasyMock.replay(proxy);
|
||||
|
||||
ActionContext.getContext().setActionInvocation(invocation);
|
||||
createMocks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,5 +379,6 @@ public class TooltipTest extends AbstractUITagTest {
|
||||
initDispatcher(new HashMap<String,String>(){{
|
||||
put("configProviders", TestConfigurationProvider.class.getName());
|
||||
}});
|
||||
createMocks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<script type="text/javascript" src="/struts/xhtml/validation.js"></script>
|
||||
<script type="text/javascript" src="/struts/utils.js"></script>
|
||||
<form id="myAction" name="myForm" onsubmit="submitMe(); return validateForm_myAction();" action="/myAction.action" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8" onreset="clearErrorMessages(this);clearErrorLabels(this);">
|
||||
<form id="testAction" name="myForm" onsubmit="submitMe(); return validateForm_testAction();" action="/testAction.action" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8" onreset="clearErrorMessages(this);clearErrorLabels(this);">
|
||||
<table class="wwFormTable"> <tr>
|
||||
<td class="tdLabel"></td>
|
||||
<td> <script type="text/javascript" src="/struts/optiontransferselect.js"></script>
|
||||
<table>
|
||||
<tr><td>
|
||||
<select name="myUpDownSelectTag" size="5" id="myAction_myUpDownSelectTag" multiple="multiple">
|
||||
<select name="myUpDownSelectTag" size="5" id="testAction_myUpDownSelectTag" multiple="multiple">
|
||||
</select>
|
||||
<input type="hidden" id="__multiselect_myAction_myUpDownSelectTag" name="__multiselect_myUpDownSelectTag"value=""/>
|
||||
<input type="hidden" id="__multiselect_testAction_myUpDownSelectTag" name="__multiselect_myUpDownSelectTag"value=""/>
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
<input type="button" value="^" onclick="moveOptionUp(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="v" onclick="moveOptionDown(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="*" onclick="selectAllOptions(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="^" onclick="moveOptionUp(document.getElementById('testAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="v" onclick="moveOptionDown(document.getElementById('testAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="*" onclick="selectAllOptions(document.getElementById('testAction_myUpDownSelectTag'), 'key', '');" />
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var containingForm = document.getElementById("myAction");
|
||||
var containingForm = document.getElementById("testAction");
|
||||
StrutsUtils.addEventListener(containingForm, "submit",
|
||||
function(evt) {
|
||||
var updownselectObj = document.getElementById("myAction_myUpDownSelectTag");
|
||||
var updownselectObj = document.getElementById("testAction_myUpDownSelectTag");
|
||||
selectAllOptionsExceptSome(updownselectObj, "key", "");
|
||||
}, true);
|
||||
</script>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<form id="testAction" name="testAction" action="/somecontext/testAction.action" method="post">
|
||||
<form id="testAction" name="testAction" action="/testNamespace/testAction.action" method="post">
|
||||
<table class="wwFormTable">
|
||||
</table>
|
||||
</form>
|
||||
@@ -1,19 +1,19 @@
|
||||
<script type="text/javascript" src="/struts/xhtml/validation.js"></script>
|
||||
<script type="text/javascript "src="/struts/utils.js"></script>
|
||||
<form id="myAction" name="myForm" onsubmit="submitMe(); return validateForm_myAction();" action="/myAction.action" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8" onreset="clearErrorMessages(this);clearErrorLabels(this);">
|
||||
<form id="doubleValidationAction" name="myForm" onsubmit="submitMe(); return validateForm_doubleValidationAction();" action="/doubleValidationAction.action" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8" onreset="clearErrorMessages(this);clearErrorLabels(this);">
|
||||
<table class="wwFormTable"> <tr>
|
||||
<td class="tdLabel"></td>
|
||||
<td> <script type="text/javascript" src="/struts/optiontransferselect.js"></script>
|
||||
<table>
|
||||
<tr><td>
|
||||
<select name="myUpDownSelectTag" size="5" id="myAction_myUpDownSelectTag" multiple="multiple">
|
||||
<select name="myUpDownSelectTag" size="5" id="doubleValidationAction_myUpDownSelectTag" multiple="multiple">
|
||||
</select>
|
||||
<input type="hidden" id="__multiselect_myAction_myUpDownSelectTag" name="__multiselect_myUpDownSelectTag"value=""/>
|
||||
<input type="hidden" id="__multiselect_doubleValidationAction_myUpDownSelectTag" name="__multiselect_myUpDownSelectTag"value=""/>
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
<input type="button" value="^" onclick="moveOptionUp(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="v" onclick="moveOptionDown(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="*" onclick="selectAllOptions(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="^" onclick="moveOptionUp(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="v" onclick="moveOptionDown(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="*" onclick="selectAllOptions(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
@@ -23,17 +23,17 @@
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var containingForm = document.getElementById("myAction");
|
||||
var containingForm = document.getElementById("doubleValidationAction");
|
||||
StrutsUtils.addEventListener(containingForm, "submit",
|
||||
function(evt) {
|
||||
var updownselectObj = document.getElementById("myAction_myUpDownSelectTag");
|
||||
var updownselectObj = document.getElementById("doubleValidationAction_myUpDownSelectTag");
|
||||
selectAllOptionsExceptSome(updownselectObj, "key", "");
|
||||
}, true);
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function validateForm_myAction() {
|
||||
function validateForm_doubleValidationAction() {
|
||||
var getFieldValue = function(field) {
|
||||
var type = field.type ? field.type : field[0].type;
|
||||
if(type == 'select-one' || type == 'select-multiple') {
|
||||
@@ -51,11 +51,25 @@
|
||||
}
|
||||
return field.value;
|
||||
}
|
||||
form = document.getElementById("myAction");
|
||||
form = document.getElementById("doubleValidationAction");
|
||||
clearErrorMessages(form);
|
||||
clearErrorLabels(form);
|
||||
var errors = false;
|
||||
var continueValidation=true;
|
||||
//field name: myUpDownSelectTag
|
||||
//validator name: double
|
||||
if(form.elements['myUpDownSelectTag']) {
|
||||
field = form.elements['myUpDownSelectTag'];
|
||||
var error = "bar must be between 6000.1 and 10000.1.";
|
||||
var fieldValue=getFieldValue(field);
|
||||
if(continueValidation && fieldValue != null) {
|
||||
var value = parseFloat(fieldValue);
|
||||
if(value < 6000.1 || value>10000.1 || false || false){
|
||||
addError(field, error);
|
||||
errors=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return !errors;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<script type="text/javascript" src="/struts/xhtml/validation.js"></script>
|
||||
<script type="text/javascript "src="/struts/utils.js"></script>
|
||||
<form id="myAction" name="myForm" onsubmit="submitMe(); return validateForm_myAction();" action="/myAction.action" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8" onreset="clearErrorMessages(this);clearErrorLabels(this);">
|
||||
<form id="doubleValidationAction" name="myForm" onsubmit="submitMe(); return validateForm_doubleValidationAction();" action="/doubleValidationAction.action" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8" onreset="clearErrorMessages(this);clearErrorLabels(this);">
|
||||
<table class="wwFormTable"> <tr>
|
||||
<td class="tdLabel"></td>
|
||||
<td> <script type="text/javascript" src="/struts/optiontransferselect.js"></script>
|
||||
<table>
|
||||
<tr><td>
|
||||
<select name="myUpDownSelectTag" size="5" id="myAction_myUpDownSelectTag" multiple="multiple">
|
||||
<select name="myUpDownSelectTag" size="5" id="doubleValidationAction_myUpDownSelectTag" multiple="multiple">
|
||||
</select>
|
||||
<input type="hidden" id="__multiselect_myAction_myUpDownSelectTag" name="__multiselect_myUpDownSelectTag"value=""/>
|
||||
<input type="hidden" id="__multiselect_doubleValidationAction_myUpDownSelectTag" name="__multiselect_myUpDownSelectTag"value=""/>
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
<input type="button" value="^" onclick="moveOptionUp(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="v" onclick="moveOptionDown(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="*" onclick="selectAllOptions(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="^" onclick="moveOptionUp(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="v" onclick="moveOptionDown(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="*" onclick="selectAllOptions(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
@@ -23,16 +23,16 @@
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var containingForm = document.getElementById("myAction");
|
||||
var containingForm = document.getElementById("doubleValidationAction");
|
||||
StrutsUtils.addEventListener(containingForm, "submit",
|
||||
function(evt) {
|
||||
var updownselectObj = document.getElementById("myAction_myUpDownSelectTag");
|
||||
var updownselectObj = document.getElementById("doubleValidationAction_myUpDownSelectTag");
|
||||
selectAllOptionsExceptSome(updownselectObj, "key", "");
|
||||
}, true);
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function validateForm_myAction() {
|
||||
function validateForm_doubleValidationAction() {
|
||||
var getFieldValue = function(field) {
|
||||
var type = field.type ? field.type : field[0].type;
|
||||
if(type == 'select-one' || type == 'select-multiple') {
|
||||
@@ -50,21 +50,22 @@
|
||||
}
|
||||
return field.value;
|
||||
}
|
||||
form = document.getElementById("myAction");
|
||||
form = document.getElementById("doubleValidationAction");
|
||||
clearErrorMessages(form);
|
||||
clearErrorLabels(form);
|
||||
var errors = false;
|
||||
var continueValidation = true;
|
||||
//fieldname:myUpDownSelectTag
|
||||
//validatorname:int
|
||||
//field name: myUpDownSelectTag
|
||||
//validator name: double
|
||||
if(form.elements['myUpDownSelectTag']) {
|
||||
field = form.elements['myUpDownSelectTag'];
|
||||
var error = "bar must be between 6000 and 10000.";
|
||||
var fieldValue = getFieldValue(field);
|
||||
var error = "bar must be between 6000.1 and 10000.1.";
|
||||
var fieldValue=getFieldValue(field);
|
||||
if(continueValidation && fieldValue != null) {
|
||||
if(parseInt(fieldValue) < 6000 || parseInt(fieldValue) > 10000) {
|
||||
var value = parseFloat(fieldValue);
|
||||
if(value < 6000.1 || value>10000.1 || false || false){
|
||||
addError(field, error);
|
||||
errors = true;
|
||||
errors=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<script type="text/javascript" src="/struts/xhtml/validation.js"></script>
|
||||
<script type="text/javascript "src="/struts/utils.js"></script>
|
||||
<form id="myAction" name="myForm" onsubmit="submitMe(); return validateForm_myAction();" action="/myAction.action" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8" onreset="clearErrorMessages(this);clearErrorLabels(this);">
|
||||
<form id="doubleValidationAction" name="myForm" onsubmit="submitMe(); return validateForm_doubleValidationAction();" action="/doubleValidationAction.action" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8" onreset="clearErrorMessages(this);clearErrorLabels(this);">
|
||||
<table class="wwFormTable"> <tr>
|
||||
<td class="tdLabel"></td>
|
||||
<td> <script type="text/javascript" src="/struts/optiontransferselect.js"></script>
|
||||
<table>
|
||||
<tr><td>
|
||||
<select name="myUpDownSelectTag" size="5" id="myAction_myUpDownSelectTag" multiple="multiple">
|
||||
<select name="myUpDownSelectTag" size="5" id="doubleValidationAction_myUpDownSelectTag" multiple="multiple">
|
||||
</select>
|
||||
<input type="hidden" id="__multiselect_myAction_myUpDownSelectTag" name="__multiselect_myUpDownSelectTag"value=""/>
|
||||
<input type="hidden" id="__multiselect_doubleValidationAction_myUpDownSelectTag" name="__multiselect_myUpDownSelectTag"value=""/>
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
<input type="button" value="^" onclick="moveOptionUp(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="v" onclick="moveOptionDown(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="*" onclick="selectAllOptions(document.getElementById('myAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="^" onclick="moveOptionUp(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="v" onclick="moveOptionDown(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
<input type="button" value="*" onclick="selectAllOptions(document.getElementById('doubleValidationAction_myUpDownSelectTag'), 'key', '');" />
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
@@ -23,16 +23,16 @@
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var containingForm = document.getElementById("myAction");
|
||||
var containingForm = document.getElementById("doubleValidationAction");
|
||||
StrutsUtils.addEventListener(containingForm, "submit",
|
||||
function(evt) {
|
||||
var updownselectObj = document.getElementById("myAction_myUpDownSelectTag");
|
||||
var updownselectObj = document.getElementById("doubleValidationAction_myUpDownSelectTag");
|
||||
selectAllOptionsExceptSome(updownselectObj, "key", "");
|
||||
}, true);
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function validateForm_myAction() {
|
||||
function validateForm_doubleValidationAction() {
|
||||
var getFieldValue = function(field) {
|
||||
var type = field.type ? field.type : field[0].type;
|
||||
if(type == 'select-one' || type == 'select-multiple') {
|
||||
@@ -50,13 +50,13 @@
|
||||
}
|
||||
return field.value;
|
||||
}
|
||||
form = document.getElementById("myAction");
|
||||
form = document.getElementById("doubleValidationAction");
|
||||
clearErrorMessages(form);
|
||||
clearErrorLabels(form);
|
||||
var errors = false;
|
||||
var continueValidation = true;
|
||||
//fieldname:myUpDownSelectTag
|
||||
//validatorname:double
|
||||
//field name: myUpDownSelectTag
|
||||
//validator name: double
|
||||
if(form.elements['myUpDownSelectTag']) {
|
||||
field = form.elements['myUpDownSelectTag'];
|
||||
var error = "bar must be between 6000.1 and 10000.1.";
|
||||
|
||||
@@ -62,11 +62,13 @@ import static org.junit.Assert.assertNotNull;
|
||||
|
||||
|
||||
public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
|
||||
protected MockHttpServletResponse response;
|
||||
protected MockHttpServletRequest request;
|
||||
protected MockPageContext pageContext;
|
||||
protected MockServletContext servletContext;
|
||||
protected Map<String, String> dispatcherInitParams;
|
||||
protected Dispatcher dispatcher;
|
||||
|
||||
protected DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
|
||||
@@ -178,8 +180,7 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
* Finds an ActionMapping for a given request
|
||||
*/
|
||||
protected ActionMapping getActionMapping(HttpServletRequest request) {
|
||||
return Dispatcher.getInstance().getContainer().getInstance(ActionMapper.class).getMapping(request,
|
||||
Dispatcher.getInstance().getConfigurationManager());
|
||||
return container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,10 +196,9 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
* Injects dependencies on an Object using Struts internal IoC container
|
||||
*/
|
||||
protected void injectStrutsDependencies(Object object) {
|
||||
Dispatcher.getInstance().getContainer().inject(object);
|
||||
container.inject(object);
|
||||
}
|
||||
|
||||
|
||||
protected void setupBeforeInitDispatcher() throws Exception {
|
||||
}
|
||||
|
||||
@@ -232,7 +232,6 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
super.setUp();
|
||||
initServletMockObjects();
|
||||
setupBeforeInitDispatcher();
|
||||
@@ -248,11 +247,12 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
}
|
||||
|
||||
protected Dispatcher initDispatcher(Map<String, String> params) {
|
||||
Dispatcher du = StrutsTestCaseHelper.initDispatcher(servletContext, params);
|
||||
configurationManager = du.getConfigurationManager();
|
||||
dispatcher = StrutsTestCaseHelper.initDispatcher(servletContext, params);
|
||||
configurationManager = dispatcher.getConfigurationManager();
|
||||
configuration = configurationManager.getConfiguration();
|
||||
container = configuration.getContainer();
|
||||
return du;
|
||||
container.inject(dispatcher);
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,8 +267,11 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
|
||||
super.tearDown();
|
||||
if (dispatcher != null && dispatcher.getConfigurationManager() != null) {
|
||||
dispatcher.cleanup();
|
||||
dispatcher = null;
|
||||
}
|
||||
StrutsTestCaseHelper.tearDown();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ public abstract class StrutsTestCase extends XWorkTestCase {
|
||||
protected MockPageContext pageContext;
|
||||
protected MockServletContext servletContext;
|
||||
protected Map<String, String> dispatcherInitParams;
|
||||
protected Dispatcher dispatcher;
|
||||
|
||||
protected DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
|
||||
@@ -177,8 +178,7 @@ public abstract class StrutsTestCase extends XWorkTestCase {
|
||||
* Finds an ActionMapping for a given request
|
||||
*/
|
||||
protected ActionMapping getActionMapping(HttpServletRequest request) {
|
||||
return Dispatcher.getInstance().getContainer().getInstance(ActionMapper.class).getMapping(request,
|
||||
Dispatcher.getInstance().getConfigurationManager());
|
||||
return container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,10 +194,9 @@ public abstract class StrutsTestCase extends XWorkTestCase {
|
||||
* Injects dependencies on an Object using Struts internal IoC container
|
||||
*/
|
||||
protected void injectStrutsDependencies(Object object) {
|
||||
Dispatcher.getInstance().getContainer().inject(object);
|
||||
container.inject(object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the configuration settings, XWork configuration, and
|
||||
* message resources
|
||||
@@ -206,7 +205,7 @@ public abstract class StrutsTestCase extends XWorkTestCase {
|
||||
super.setUp();
|
||||
initServletMockObjects();
|
||||
setupBeforeInitDispatcher();
|
||||
Dispatcher dispatcher = initDispatcher(dispatcherInitParams);
|
||||
dispatcher = initDispatcher(dispatcherInitParams);
|
||||
setupAfterInitDispatcher(dispatcher);
|
||||
}
|
||||
|
||||
@@ -235,6 +234,11 @@ public abstract class StrutsTestCase extends XWorkTestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
// maybe someone else already destroyed Dispatcher
|
||||
if (dispatcher != null && dispatcher.getConfigurationManager() != null) {
|
||||
dispatcher.cleanup();
|
||||
dispatcher = null;
|
||||
}
|
||||
StrutsTestCaseHelper.tearDown();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -206,7 +206,7 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
|
||||
|
||||
// For testability
|
||||
if (factory == null) {
|
||||
factory = dispatcherUtils.getConfigurationManager().getConfiguration().getContainer().getInstance(ActionProxyFactory.class);
|
||||
factory = dispatcherUtils.getContainer().getInstance(ActionProxyFactory.class);
|
||||
}
|
||||
portletNamespace = cfg.getInitParameter("portletNamespace");
|
||||
if (LOG.isDebugEnabled()) {
|
||||
@@ -374,7 +374,7 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
|
||||
extraContext.put(ActionContext.SESSION, sessionMap);
|
||||
extraContext.put(ActionContext.APPLICATION, applicationMap);
|
||||
|
||||
String defaultLocale = dispatcherUtils.getContainer().getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
|
||||
String defaultLocale = container.getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
|
||||
Locale locale;
|
||||
if (defaultLocale != null) {
|
||||
locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
|
||||
|
||||
@@ -82,6 +82,8 @@ public class PortletUrlTagTest extends MockObjectTestCase {
|
||||
|
||||
Mock mockActionInvocation = null;
|
||||
|
||||
private Dispatcher dispatcher;
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(PortletUrlTagTest.class);
|
||||
}
|
||||
@@ -90,12 +92,12 @@ public class PortletUrlTagTest extends MockObjectTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
Dispatcher du = new Dispatcher(null, new HashMap());
|
||||
du.init();
|
||||
Dispatcher.setInstance(du);
|
||||
dispatcher = new Dispatcher(null, new HashMap());
|
||||
dispatcher.init();
|
||||
Dispatcher.setInstance(dispatcher);
|
||||
|
||||
stack = du.getContainer().getInstance(ValueStackFactory.class).createValueStack();
|
||||
stack.getContext().put(ActionContext.CONTAINER, du.getContainer());
|
||||
stack = dispatcher.getContainer().getInstance(ValueStackFactory.class).createValueStack();
|
||||
stack.getContext().put(ActionContext.CONTAINER, dispatcher.getContainer());
|
||||
ActionContext context = new ActionContext(stack.getContext());
|
||||
ActionContext.setContext(context);
|
||||
|
||||
@@ -166,6 +168,14 @@ public class PortletUrlTagTest extends MockObjectTestCase {
|
||||
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
if (dispatcher != null && dispatcher.getConfigurationManager() != null) {
|
||||
dispatcher.cleanup();
|
||||
dispatcher = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void testEnsureParamsAreStringArrays() {
|
||||
Map params = new HashMap();
|
||||
params.put("param1", "Test1");
|
||||
|
||||
Reference in New Issue
Block a user