I'm a noobie in Spring MVC
To make Spring MVC 3 Validation fully work, Must it be that the Model Class (e.g. User class) to have a commandName as 'user'?
can't it be changed?
Whenever i change the commandName (e.g. 'userx'), the error messages in the JSP does not show.
Is it a prerequisite that the commandName must have a naming convention for its Class name?
I'm sorry if this que开发者_JAVA百科stion is already answered in the Spring Docs or here in stackoverflow, it seems that I can't find the answer myself. Thanks
EDIT: Here is my form Command name is "searchClientForm", thus the corresponding Class name is SearchClientForm.java
<form:form action="search.html" commandName="searchClientForm" method="post" class="tabform">
<h2>Client Maintenance</h2>
<div class="spacer"></div>
<div class="clear">
<label class="error"><c:out value="${errorMessage}"/></label>
</div>
<div class="spacer"></div>
<div class="clear">
<label for="fieldCode">Filter: </label>
<form:select path="fieldCode" items="${searchFields}" itemLabel="description" itemValue="key" id="fieldCode" />
<label for="searchValue">Search: </label>
<form:input path="search" id="searchValue" />
<input type="submit" value="Go"/>
<form:errors path="search" element="label" cssClass="error"/>
</div>
<div class="clear"></div>
</form:form>
The command name and class should be the same (command starts from lower case letter). You can extend the original class. public class User extends SearchClientForm {} and place it in model as "user".
精彩评论