I have a JSp page, with validator and controller. When i use <form method="GET"> in place of post my validator stop responding, i.e may be validator is working but it's not showing any message which comes from validator earlier like user name is empty. I am using following code:
validator:
context.xmlCode:package com.sachin.login; import org.springframework.validation.Errors; import org.springframework.validation.Validator; public class SignInValidator implements Validator{ public boolean supports(Class checkMe) { return checkMe.equals(SignIn.class); } public void validate(Object object, Errors errors) { SignIn signin=(SignIn)object; if (signin == null) { errors.rejectValue("SignIn", "signIn.error.novalue", null,"Value required."); } String name=signin.getUname(); String password=signin.getPassword(); if ((name == null) || (name.length() < 1)) { errors.rejectValue("uname", "signIn.error.name.missing","The name field is missing."); } if((password==null)||(password.length()<1)) { errors.rejectValue("password","signIn.error.comments.missing","Password is missing."); } } }
Code:<bean id="signInController" class="com.sachin.login.SignInController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>SignIn</value></property> <property name="commandClass"><value>com.sachin.login.SignIn</value></property> <property name="validateOnBinding"><value>true</value></property> <property name="validator"><ref bean="signInValidator"/></property> <property name="formView"><value>signIn</value></property> <property name="successView"><value>success</value></property> <property name="bindOnNewForm"><value>false</value></property> <property name="signInDao"><ref bean="signInDao" /></property> </bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename"><value>messages</value></property> </bean>
messages.properties is the file from where messages are shown.
my jsp is:
Code:<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Login - Sign In</title> <link href="timex.css" rel="stylesheet" type="text/css"> </head> <form method="post"> <table width="85%" border="1" align="center" cellpadding="0" cellspacing="0"> <tr> <td> <table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" bordercolor="#CCCCCC"> <tr bgcolor="#C2DCEB" valign="middle"> <td width="90%" valign="middle"> <h1>Sign In</h1> </td> </tr> <tr> <td colspan="2"> <center><spring:bind path="SignIn.*"> <c:if test="${not empty status.errorMessages}"> <c:forEach var="error" items="${status.errorMessages}"> <font color="red"><c:out value="${error}" escapeXml="false" /> </font> <br /> </c:forEach> </c:if> </spring:bind> <!-- status messages --> <c:if test="${not empty message}"> <font color="green"><c:out value="${message}" /></font> <c:set var="message" value="" scope="session" /> </c:if></center> <div align="center"> <p>Please provide your authentication information below.</p> <p>Employee Id: <spring:bind path="SignIn.uname"> <input name="uname" value='<c:out value="${status.value}"/>' type="text" size="6" maxlength="6"> </spring:bind> Password: <spring:bind path="SignIn.password"> <input name="password" value='<c:out value="${status.value}"/>' type="password" size="8" maxlength="10"> </spring:bind> <input type="submit" name="Submit" value="Sign In"></p> </div> <br> </form> </td> </tr> <tr> <td bgcolor="#C2DCEB"><a href="signupform.htm">SignUp</a> <a href="forgotpassword.htm">Forgot Password</a></td> </tr> </table> </td> </tr> </table> </body> </html>


Reply With Quote
