Announcement Announcement Module
Collapse
No announcement yet.
Displaying Error from message resource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaying Error from message resource

    Can anybody tell me how to display a error message that was added to the errors object, I can see the error code, default message etc, but couldn't get to the text in the actual message resources. I forward the user to an error page when there is some exception that happen while process a form. I put in the view the errors object but couldn't get the error out, I been playing with this for a while now and it is just not going anywhere.


    Code:
    public static final String ERRORMESSAGE = "error.exception.databaseError.1010";
    
     try {           
             //try something
          } 
    catch (DatabaseErrorException e) {
    
    errors.reject(ERRORMESSAGE, null, "");
    
    return new ModelAndView(getFormErrorView(), "dictionary", errors );
    On my message resource:
    Code:
    error.exception.databaseError.1010=The current user have been deleted
    on the FormErrorView page, I try to display the error message and couldn't figure out why. Everything works on form pages like if there is a field input error but not on the forwarded view page. Nothing seems to work. I can get to the error code and default message but just can't get to the actual text in the resource message file.

    None of these display anything

    Code:
    <spring&#58;bind path="dictionary">
    	<c&#58;forEach items="$&#123;status.errorMessages&#125;" var="error">
        Error code&#58; <c&#58;out value="$&#123;error&#125;"/><br>
        </c&#58;forEach>
    </spring&#58;bind>
        
    <spring&#58;hasBindErrors name="dictionary">
        <spring&#58;bind path="dictionary">
         
          <c&#58;forEach items="$&#123;status.errorMessages&#125;" var="error">
            $&#123;error&#125;<br/>
          </c&#58;forEach>
          
        </spring&#58;bind>
    
    </spring&#58;hasBindErrors>
    This one display some error but not what I want, the command object's name is "move"

    Code:
    <c&#58;forEach items="$&#123;dictionary.globalErrors&#125;" var="error">
    	<c&#58;out value="$&#123;error&#125;"/>
    </c&#58;forEach>
    
    Error in object 'move'&#58; 
    codes=&#91;error.exception.databaseError.1010.move,error.exception.databaseError.1010&#93;; arguments=&#91;null&#93;; defaultMessage=&#91;&#93; Error in object 'dictionary'

  • #2
    Mine works using the original form...
    Code:
    errors.reject&#40;ERRORMESSAGE,null,"no default"&#41;;
    Map model = new HashMap&#40;&#41;;
    model.putAll&#40;errors.getModel&#40;&#41;&#41;;
    return new ModelAndView&#40;getFormView&#40;&#41;, model&#41;;
    (Maybe rename ERRORMESSAGE to ERRORCODE)

    Code:
    <spring&#58;bind path="command">
      <span class="inputError"><c&#58;out value="$&#123;status.errorMessage&#125;"/></span>
    </spring&#58;bind>
    If you need a completly separate page to display the error, try using an exception resolver:
    Code:
    <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    	<property name="exceptionMappings">
    		<props>
    			<prop key="org.springframework.dao.DataAccessException">dataAccessFailure</prop>
    			<prop key="org.yourcompany.DatabaseErrorException ">dataAccessFailure</prop>
    		</props>
    	</property>
    </bean>
    Code:
    dataAccessFailure.class=org.springframework.web.servlet.view.JstlView
    dataAccessFailure.url=/WEB-INF/jsp/dataAccessFailure.jsp

    HTH

    Comment


    • #3
      Thanks

      Katentim

      Thanks alot! It works now.

      Comment


      • #4
        Actually, I should have used 'showForm' so:

        Code:
        errors.reject&#40;ERRORMESSAGE,null,"no default"&#41;;
        Map model = new HashMap&#40;&#41;;
        model.putAll&#40;errors.getModel&#40;&#41;&#41;;
        return new ModelAndView&#40;getFormView&#40;&#41;, model&#41;;
        should be:

        Code:
        errors.reject&#40;ERRORMESSAGE,null,"no default"&#41;;
        return showForm&#40;request, response, errors&#41;;

        Comment

        Working...
        X