Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Validator not responding.

  1. #1

    Default Validator not responding.

    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:
    Code:
    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.");
    	        }
    	}
    }
    context.xml

    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> &nbsp;Password: <spring:bind path="SignIn.password">
              <input name="password"
                value='<c:out value="${status.value}"/>' type="password" size="8"
                maxlength="10">
            </spring:bind> &nbsp;<input type="submit" name="Submit"
              value="Sign In"></p>
            </div>
            <br>
            </form>
            </td>
          </tr>
          <tr>
            <td bgcolor="#C2DCEB"><a href="signupform.htm">SignUp</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="forgotpassword.htm">Forgot Password</a></td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
    </body>
    </html>

  2. #2

    Question Where is the "signInValidator" bean tag

    <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.Resourc eBundleMessageSource">
    <property name="basename"><value>messages</value></property>
    </bean>


    In above code you have writen the properties for SignInController Bean. for this bean you are setting the validator. for this you are refering the some other bean. i.e signInValidator bean. i would llike to see this bean first..
    Last edited by ArunD; Dec 18th, 2006 at 03:27 AM.

  3. #3

    Default

    Quote Originally Posted by ArunD View Post
    <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.Resourc eBundleMessageSource">
    <property name="basename"><value>messages</value></property>
    </bean>


    In above code you have writen the properties for SignInController Bena. for this bean you are setting the validator. for this you are refering the some there bean. i.e signInValidator bean. i would llike to see this bean first..
    <bean id="signInValidator" class="com.sachin.login.SignInValidator"/>

  4. #4

    Exclamation then it should work

    You context dont have any problem, problem might be in validator class ..

  5. #5

    Default

    Hi Sachin,
    Try setting the bind on new form property to true.
    Perseverance pays,
    only if you are in the right direction.

  6. #6

    Smile is It Server side validation ?

    Is Using validator interface for input form validation runs on server side ?

    Is this server side validation ?

  7. #7

    Default

    Hey ArunD,
    Spring Validation happens in the server side, its not client side validator. This validation happens before the request goes to the controller.
    Perseverance pays,
    only if you are in the right direction.

  8. #8

    Smile ohh

    that means it is working on server side, but before the Controller, is It?

    Ok now it is cleare.

    one more thing, how to integrate multiple actions in multiaction controller ?

  9. #9

    Default

    If you have multiple action map it with multiple controllers in handler mapping. Depending on the action the corresponding controller will be called. The mapping will come in web_app-servlet.xml for spring mvc and portle_name-portlet.xml in Spring portlets
    Perseverance pays,
    only if you are in the right direction.

  10. #10

    Smile i got it, but please explain with sample xml code for mapping

    yes, i got the idea of having the multiaction controller, but please explain with sample xml entries or mappings.
    so that technicaly it will be cleare

    Thanks for giving such quick response
    ARUN D.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •