PDA

View Full Version : How to display a global error in jsp?


lee3star
Jul 16th, 2007, 10:29 AM
Hi guys,

I'm a newbie just from Struts to Spring2.

In my controller class, I have the following code adding a global error:

try {
user = userService.authenticate(form.getLoggingName(), form.getPassword());
} catch (UserAuthenticationException e) {
errors.reject(e.getMessage());
form.setPassword(null);
request.setAttribute(getCommandName(), form);
return new ModelAndView(getFormView());
}

The question is how to display the error in jsp page?

I have tried:

1) <form:errors />
2) <form:errors path="commandName" />

but no luck.

Can anyone give me a hint on this??

Any input is welcome. thanks.

infinity2heaven
Jul 16th, 2007, 11:23 AM
I've blogged about this here - http://reverttoconsole.com/archives/118
Hope it helps

lee3star
Jul 16th, 2007, 09:39 PM
Thanks infinity2heaven.

However,that's not what I meant.

The 'global error' I was referring is:

http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/validation/BindException.html#reject(java.lang.String)

org.springframework.validation.BindException

public void reject(String errorCode)

Description copied from interface: Errors
Register a global error for the entire target object, using the given error description.

Specified by:
reject in interface Errors

Parameters:
errorCode - error code, interpretable as a message key

It says the global error is for the entire target object. In my understanding, it's the form object.

My question is how to output the error for the target object in a jsp page.

Please help.