• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

using SimpleFormController

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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
saikiran
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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:

Validator:

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");



jsp:

<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}"/>
</c:if>

</spring:bind>



Controller:

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
.getPassword());
if (isExist) {
request.getSession().setAttribute("userName", login.getName());
return new ModelAndView(getSuccessView());
} else {
return new ModelAndView(getFailedView());
}



servlet-action.xml:

<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>
</bean>

hope this helps.....


Andy
 
Saikiran Madhavan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:-

email
firstname
lastname
city
state
zip
address1
address2
phone

etc....

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

thanks again...
 
anand tiwari
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

andy
 
Saikiran Madhavan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

regards
saikiran
 
anand tiwari
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic