Announcement Announcement Module
Collapse
No announcement yet.
globalError get the message in ResourceBundleMessageSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • globalError get the message in ResourceBundleMessageSource

    Hi,

    In my form, I ve 2 date fields which I define a "From" date and a "To" date.
    When the user give a "From" date greater than the "To" date, I would like to throw an error.

    So in my validator, I have :
    Code:
    public void validate(Object object, Errors errors) {
    		SomeObject so = (SomeObject ) object;
    		Date date1 = so .getDateBegin();
    		Date date2 = so .getDateEnd();
    		if (null != date1 && null != date2 && date1.getTime() > date2.getTime()) {
    			errors.reject("wrong dates",
    					"The From date can not be greater than the To date");
    		}
    	}
    And in my jsp I have :
    Code:
    <spring&#58;hasBindErrors name="command">
    <c&#58;out value="$&#123;errors.globalError.defaultMessage&#125;" />
    </spring&#58;hasBindErrors>
    In my JSP, I take the first globalError (there could be only one), but I ve seen in the API that I can only display the default message with the method "getDefaultMessage" (the one defined in the validator) and not the one defined in the ResourceBundleMessageSource with the code "wrong dates".

    Is there a way to display the message defined in the ResourceBundleMessageSource ?

    bye

  • #2
    Yes. Try,
    Code:
    <spring&#58;bind path="command">
      <c&#58;out value="$&#123;status.errorMessage&#125;"/>
    </spring&#58;bind>
    Also, the error code (property key) shouldn't have whitespace. Try changing it to:
    Code:
    wrongDates

    Comment


    • #3
      Hi,

      Thx for your answer katentim, it works well

      But I have another problem :

      The "wrongDates" error should be thrown and displayed in my web page only when I have 2 valid dates and "From date" > "To date".
      But when I have this error displayed and then I fill a wrong date (like "aaa" instead of a valid date like "20/01/2004"), the field error is displayed (this is normal) but the "wrongDates" error is still displayed too.. :?

      How can I made this error not to be displayed when I have an "invalid date" error?

      Comment


      • #4
        Hi,

        In my form controller, I have removed this lines as I don't need session:
        Code:
        public ETradeQuoteController&#40;&#41; &#123;
          setSessionForm&#40;true&#41;;
        &#125;
        And all works well! 8)

        Comment

        Working...
        X