I'm new to Spring, and I have a problem. I have a form which is used to send information to the controller. I don't need or want to have a bean backing up the form so I left the commandName
attribute in the form blank like this:
<form:form action="getReportFile.html" method="post">
<table>
<tr>
<td><form:label path="field1">Field1:</form:label></td>
</tr>
<tr>
<td><form:select path="field1" items="${FieldMap}" />
</td>
</tr>
<tr>
<td><form:label path="field2">Field2:</form:label></td>
</tr>
<tr>
<td><form:input path="field2"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
I'm getting the following error:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
I could see here that when you don't give a value to commandName
it uses the default 'command'
, but then, Do I have to configure anything else? should I put a 'command'
bean in the dispatcher-servlet.xml
? How would that bean?
I just want a form to send the information to the controller. Do I really have to create a bean to back it?
If you don't need a command object at all, then avoid the Spring form and simply use an HTML form.
So, change
<form:form action="getReportFile.html" method="post">
.
.
.
</form:form>
to
<form action="getReportFile.html" method="post">
.
.
.
</form>
The command object is indeed not mandatory. It is mandatory only if you use the Spring's form like <form:form></form:form>
using the following library.
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
You have to receive the request parameters using the request.getParameter("paramName")
method, if you use an HTML form.
if you don't have a form backing bean, you can't use the Spring tag since it does require one! Your "path" attribute on that tag is supposed to specify the path to the model bean's property for data binding.
http://forum.springsource.org/showthread.php?83532-how-to-have-form-without-command-object&p=279807#post279807
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With