Announcement Announcement Module
Collapse
No announcement yet.
validator and onSubmit does not display messages in my jsp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • validator and onSubmit does not display messages in my jsp

    is there something wrong with my code?
    i cant seem to display error messages..

    my Validator
    Code:
        public boolean supports(Class clazz) {
            return TblMstUser.class.isAssignableFrom(clazz);
        }
    
        public void validate(Object obj, Errors errors) {
            
            ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userName", "required", "required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passWord", "required", "required");
        	
        }

    my jsp
    Code:
    <spring:bind path="userName">
                   <c:if test="${status.error}">
                    <tr>
                     <td class="txt_red"><c:out value="${status.errorMessage}"/></td>
                    </tr>
                   </c:if>
                   <tr>
                    <td class="txt_11 pad_10_right"><strong>Username :</strong></td>
                    <td><input id="userName" name="userName" type="text" class="txt_field_11" value="<c:out value="${status.value}"/>" style="width:150px;"></td>
                   </tr>
                  </spring:bind>

    my servlet.xml
    Code:
        <bean id="loginPortalForm" class="com.eportal.controller.LoginPortalForm" lazy-init="default" autowire="default" dependency-check="default">
    	  <property name="formView" 	 value="loginPortalForm" /> 
    	  <property name="successView" 	 value="loginSuccessView" />
    	  <property name="sessionForm"   value="true" />
    	  <property name="validator"     ref="loginPortalValidator"/>
    	  <property name="tblMstUserDao" ref="tblMstUserDao"/>
    	</bean>
    also if it passes my validator and proceeds to onSubmit still no error messages.

    my onSubmit
    Code:
    	@Override
        protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
                Object command, BindException errors) throws Exception {
    
        	TblMstUser user = (TblMstUser) command;
        	
        	user = (TblMstUser) getTblMstUserDao().exists(user.getUserName(), user.getPassWord());
        	
        	if (user == null) {
        		errors.rejectValue("userName", "accessDenied");
                return showForm(request, response, errors);
        	}
    
        	//Set session here..
       	
        	return new ModelAndView(getSuccessView());
        }

    also, when login is a success "return new ModelAndView(getSuccessView());" does not forward to the success page
    Last edited by long_ranger; Jul 5th, 2007, 04:22 AM. Reason: forgot about the success par of onSubmit

  • #2
    my servlet.xml
    Code:

    <bean id="loginPortalForm" class="com.eportal.controller.LoginPortalForm" lazy-init="default" autowire="default" dependency-check="default">
    <property name="formView" value="loginPortalForm" />
    <property name="successView" value="loginSuccessView" />
    <property name="sessionForm" value="true" />
    <property name="validator" ref="loginPortalValidator"/>
    <property name="tblMstUserDao" ref="tblMstUserDao"/>
    </bean>
    Hi ,
    Iam assuming you are using SimpleFormController
    there are two properties that you haven't defined.
    1. commandName(optional) defaults to command.
    2. commandClass is mandatory,

    Iam surprised that you are not getting a runtime exception, the message must be as follows" Cannot create command without commandClass being set - " +
    "either set commandClass or (in a form controller) override formBackingObject")"

    If you are using spring 2.0.x then try using spring form tags rather than spring bind, the form tgas are far better and concise.

    Comment


    • #3
      yes i am using SimpleFormController.

      i have set my command class

      Code:
      	public LoginPortalForm () {
      		setCommandName("login");
      		setCommandClass(TblMstUser.class);
      	}
      this is my spring version "spring-framework-2.0.4"
      but when i use spring:form tag my IDE says not found.
      i checked the api. there is no form tag also.

      i'll try downloading another Spring release.
      by the way. what jars do i need? i only have spring.jar in my application

      Thank you

      Comment


      • #4
        Hi,

        you can use the following in the jsp's.
        you would only need the spring.jar
        Code:
        <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
        
        <form:form commandName="login"/>
        
        <form:input path="userName"/>
        <form:password path="passWord"/>
        <input type="submit"/>
        
        </form:form>

        Comment

        Working...
        X