PDA

View Full Version : plain error messages on form validation


mariuss
Aug 30th, 2005, 04:05 PM
Hi,

Is there a way to set plain, hard coded, error messages on form validation?

The only way I could find so far was to set error codes and these are supposed to be looked up in some properties file. I really don't want any of this overhead, I just want to send a plain error message.

Setting the default defaulMessage does not seem to make any difference.

I am using Spring 1.1.5.

Thanks,
Marius

mariuss
Aug 30th, 2005, 06:40 PM
I was checking the sample code. The petclinic app does have message resource bundles. But the jpetsore app does not have any and it does use codes. How are these resolved? :?:

vinaygajjar
Aug 31st, 2005, 11:14 AM
you could use

reject(String errorCode, String defaultMessage)
OR
rejectValue(String field, String errorCode, String defaultMessage)

in your validation. Keep errorcode as an empty string. And put your message in defaultMessage field. On your view part (jsp) display defaultMessage from error object.

mariuss
Aug 31st, 2005, 12:37 PM
This is exactly what I tried.

I tried setting the code to an empty string or to null. In both cases Spring throws an exception: org.springframework.context.NoSuchMessageException

:?