wood burning stoves 2.0*
The moose likes Other Application Frameworks and the fly likes using SimpleFormController Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "using SimpleFormController" Watch "using SimpleFormController" New topic

using SimpleFormController

Saikiran Madhavan

Joined: May 15, 2006
Posts: 28

i just want to create a simple registration page using Spring/JSP.Since its a form submission i want to use SimpleFormController for this activity.

I am having the 4 following files:-

- registerForm.jsp

- RegisterCommand.java

- RegisterFormController.java (SimpleFormController)

- RegisterFormValidator.java

actually, i am new to Spring and i have not able to understand SimpleFormController from the documentation site, can anyone help me out with this regard about what exactly all these files will hold and how the flow will go.

thanks and regards
anand tiwari

Joined: Jun 22, 2007
Posts: 22

The files you have mentioned will hold the following contents:

1) Validator---> The validations you want to keep for your form fields.
2) Command---> your bean object
3) Controller---> Simpleformcontroller
4) jsp---> the jsp file with spring:bind tags associated with the corresponding fields.

I am giving the sample code as follows:


public class LoginValidator implements Validator {

private static final int MINIMUM_PASSWORD_LENGTH = 4;

public boolean supports(Class beanName) {
return beanName.equals(Login.class);

public void validate(Object target, Errors errors) {
Login login = (Login) target;

ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name","field.required", "usrname required");


<spring:bind path="login.name">
<input type="text" name="name"
class="LoginTextBox" value="<c ut value="${status.value}"/>" />
<c:if test="${status.error}">
<c:set var="errormsg" value="${status.errorMessage}"/>



protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object obj, BindException exp)
throws Exception {
if (request.getSession().getAttribute("userName") == null) {
Login login = (Login) obj;
boolean isExist = loginservice.isValid(login.getName(), login
if (isExist) {
request.getSession().setAttribute("userName", login.getName());
return new ModelAndView(getSuccessView());
} else {
return new ModelAndView(getFailedView());


<bean id="loginController" class="com.lbadmin.web.LoginController">
<property name="formView"><value>login</value></property>
<property name="successView"><value>redirect:/adminHome.do</value></property>
<property name="failedView"><value>fail</value></property>
<property name="commandClass"><value>com.lbadmin.model.Login</value></property>
<property name="commandName"><value>login</value></property>
<property name="loginservice"><ref bean="loginService"/></property>
<property name="validator"><ref bean="loginValidator"/></property>

hope this helps.....

Saikiran Madhavan

Joined: May 15, 2006
Posts: 28
hi Andy,

thank you for your reply.

Actually, i just want to register a new user, for this usecase, what will be the Command object POJO looks like.

I am getting the following parameters from the registration form:-



the logic you have given for the login page is a good one to look at.

thanks again...
anand tiwari

Joined: Jun 22, 2007
Posts: 22
thanks a lot..

The fields that you have mentioned will all form your bean obejct. For example an object like person.java, you need to define the getter and setter methods for all the properties. Also remember one thing, if you are using the spring:bind tag in your jsp, the jsp field names should be same as the bean obejct properties.

Saikiran Madhavan

Joined: May 15, 2006
Posts: 28
hi all,

i want to create a jsp form using spring-form.tld. I am not sure what is wrong with this piece of code i am writting (newbee).

the error i am getting is given below:

this is my FormController file

my xxx-servlet.xml file is as below

My userRegistration.jsp is given below:

showing only part of the code here

My command object is as below:

can anyone help me out, why i am getting this error and how to recity it.

anand tiwari

Joined: Jun 22, 2007
Posts: 22

I cannot see the spring:bind tag in the code snippet you have pasted for your jsp page. Can you please use the jsp code, the one i pasted before and check it?
jQuery in Action, 2nd edition
subject: using SimpleFormController