Geek
Geek

Reputation: 3329

handling error messages in action class

I have a scenario where a particular method has a error message but it also returns a boolean and down the code there is another method specific to display error messages and it is initialised to action errors. something like foll.

if(abc())
{
form.set(soemthing...);
}
///
///
errors = validate();

if (!errors.isEmpty()) {
saveErrors(request, errors);

public boolean abc()
{
////
errors.add(ActionErrors.GLOBAL_ERROR, ....
return true;
}

From above code function abc() returns an error but since down the code errors are again set to someother value the error from abc is not getting printed. I cant put all the validations in a single method because of another constraint. How do i handle this and disaply error message in abc().

Upvotes: 0

Views: 608

Answers (1)

Gustavo
Gustavo

Reputation: 531

you can try something like:

public object validate(List<Error> errors) {
    /*some code*/
    error.add(/*error generated in here*/);
}

this way you dont get a new instance of errors when validate is called

Upvotes: 1

Related Questions