Announcement Announcement Module
Collapse
No announcement yet.
Cannot display errors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot display errors

    Hi forum,
    I am new to this Spring business but I find it hard to track down why things don't work as expected...well anyway
    I actually have two problems that may be related....

    1) I am trying to display validator error messages using the bind tag and nothing is shown when the validator rejects the binding. I know my validator fails the submission because onSubmit() isn't called when the values are empty however the form view renders without the original values or the error messages...I know its me but I don't know where to start.
    My Form:
    Code:
    public class FindRegistryForm extends AbstractRegistrationForm{
        private String selectView;
    
        public FindRegistryForm(){
    
            setSessionForm(true);
            setCommandClass(FindRegistryFormObject.class);
            setCommandName("findRegistryFormObj");
            setBindOnNewForm(true);
        }
        
    ......
    
        protected ModelAndView onSubmit(Object command) throws Exception{
            logger.info("Inside FindRegistryForm.onSubmit ...");
            FindRegistryFormObject formObject = (FindRegistryFormObject)command;
            
            logger.info(formObject.getFirstName());        
            logger.info(formObject.getLastName());        
            logger.info(formObject.getRegistryNo());
            
            if(!formObject.getRegistryNo().trim().equals("")){
                Registry registry = getRegistration().loadRegistry(Long.parseLong(formObject.getRegistryNo()));
                Map model = new HashMap();
                model.put(getCommandName(),formObject);
                model.put("registry",registry);
                return new ModelAndView(getSuccessView(),model);            
            }else{
                List registries = getRegistration().findRegistries(formObject.getFirstName(),formObject.getLastName());    
                Map model = new HashMap();
                model.put(getCommandName(),formObject);
                model.put("registries",registries);       
                
                logger.info("Inside registries.size: "+ registries.size());            
                return new ModelAndView(getSelectView(),model);                
            }
        
        }
    .......
    }
    My validator.validate looks like :
    Code:
        public void validate(Object object, Errors errors){
            logger.info("inside validate");
            FindRegistryFormObject formObject = (FindRegistryFormObject)object;
            ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "required", "required");
            ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "required", "required");
        }
    }
    My form view (I did a find and replace for c: --> c<colon> because the thread wouldn't let me save the post)
    Code:
    <html>
    <head>
    <%@include file="/WEB-INF/jsp/include.jsp"%>
    <title>
    <fmt:message key="title">Find Registry</fmt:message>
    </title>
    </head>
    <body bgcolor="#ffffff">
    <spring:bind path="findRegistryFormObj">
      <B>
        <c:out value="${status.errorMessages}"/>
        <c:out value="${status.errorMessage}"/>    
      </B>
    </spring:bind>
    <p>By name:</p>
    <FORM method="POST">
    <spring:bind path="findRegistryFormObj.firstName">
      <B>
        <c<colon>out value="${status.errorMessages}"/>
        <c<colon>out value="${status.errorMessage}"/>    
      </B>
      <B>First Name:</B>
      <BR>
      <INPUT type="text" maxlength="30" size="30" name="firstName" value="<c<colon>out value="${status.value}" /> ">
      <P>
    </spring:bind>
    <spring:bind path="findRegistryFormObj.lastName">
      <B>
        <c<colon>out value="${status.errorMessages}"/>
      </B>
      <B>Last Name:</B>
      <BR>
      <INPUT type="text" maxlength="30" size="30" name="lastName" value="<c<colon>out value="${status.value}" /> ">
      <P>
    </spring:bind>
    <spring:bind path="findRegistryFormObj.registryNo">  By number:
      <B>
        <c<colon>out value="${status.errorMessages}"/>
      </B>
      <p>Registry No:</p>
      <BR>
      <INPUT type="text" maxlength="30" size="30" name="registryNo" value="<c<colon>out value="${status.value}" /> ">
      <P>
    </spring:bind>
    <INPUT name="Submit" type="submit" value="Find Registrants"/>
    </FORM>
    </body>
    </html>
    my context definition: <servlet-name>-context.xml -----
    Code:
      <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
          <props>
            <prop key="/findRegistry.htm">findRegistryForm</prop>
          </props>
        </property>
      </bean>
      <!-- ========================= CONTROLLER DEFINITIONS ========================= -->
      <bean id="registrationController" class="com.bedbath.app.gr.web.GiftRegistrationController">
        <property name="registration" ref="registration"/>
      </bean>
      <bean id="findRegistryForm" class="com.bedbath.app.gr.web.FindRegistryForm">
        <property name="formView" value="findRegistry"/>
        <property name="successView" value="findRegistry"/>
        <property name="selectView" value="selectRegistry"/>
        <property name="validator" ref="findRegistryFormValidator"/>
        <property name="registration" ref="registration"/> 
      </bean>
      <bean id="findRegistryFormValidator" class="com.bedbath.app.gr.validation.FindRegistryFormValidator"/>
    </beans>
    I know this is a long post but can anyone help with my problem ?
    Last edited by springcleaning; Nov 30th, 2005, 04:03 PM.

  • #2
    Hi
    You will need to set add an asterisk in the path attribute of the bind tag.

    e.g.
    Code:
    <spring:bind path="findRegistryFormObj.*">
    <c:if test="${fn:length(status.errorMessages) > 0}" >
      <ul>
      <c:forEach items="${status.errorMessages}" var="errorMessage">
        <li><c:out value="${errorMessage}"/></li>
      </c:forEach>
      </ul>
    </c:if>
    </spring:bind>

    Comment


    • #3
      Thanks but I still cannot display the errors. Any other suggestions ?

      Comment

      Working...
      X