Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know where is the problem, let me show you my controller that works and maybe you will be able to figure out what's wrong:</p> <pre><code>public class TestController extends SimpleFormController { public TestController () { setFormView("testView"); setSuccessView("testView"); setCommandClass(TestCmd.class); setCommandName("cmd"); } protected Object formBackingObject(HttpServletRequest request)throws Exception { Object o = super.formBackingObject(request); TestCmd cmd = (TestCmd) o; return cmd; } public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { TestCmd cmd = (TestCmd) obj; log.debug("test value = " + cmd.getTestValue()); return super.onSubmit(request, response, obj, errors); } } </code></pre> <p>Form:</p> <pre><code>&lt;form method="post" action="/test.html"&gt; &lt;form:input path="cmd.testValue"/&gt; &lt;input type="submit"&gt; &lt;/form&gt; </code></pre> <p>Inside App-servlet.xml:</p> <pre><code> &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="alwaysUseFullPath" value="true" /&gt; &lt;property name="mappings"&gt; &lt;props&gt; &lt;prop key="/test.html"&gt;testController&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="testController" class="com.sample.TestController"&gt; &lt;property name="synchronizeOnSession" value="true" /&gt; &lt;property name="validator"&gt; &lt;bean class="com.sample.TestValidator"/&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>Validator:</p> <pre><code>public class TestValidator implements Validator { public boolean supports(Class clazz) { return (TestCmd.class.equals(clazz)); } public void validate(Object obj, Errors errors) { TestCmd cmd = (TestCmd) obj; if (obj == null) { // nothing } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "testValue", null, "&lt;b&gt;Value&lt;/b&gt; is required"); } } } </code></pre> <p>Command:</p> <pre><code>public class TestCmd { private String testValue; public TestCmd() { } public String getTestValue() { return testValue; } public void setTestValue(String testValue) { this.testValue = testValue; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload