Struts: how to pass error messages in Action under Validator scheme

P

PC Leung

My form extends ValidatorForm.
I add additional checking inside this form,
in addition to validator.xml and validator-rules.xml.
It works.

Now, in Action, I check the existence of record in database.
If exists, I want to display error message from ApplicationResources.properties
How can I do it? Thanks.

if (sPassword == null) {
return mapping.findForward("success");
} else {
// already exists
// display error message back to addUser.jsp
}
return mapping.findForward("addUser");
 
M

Murray

if (sPassword == null) {
return mapping.findForward("success");
} else {
// already exists
// display error message back to addUser.jsp
}
return mapping.findForward("addUser");

ActionErrors errors = new ActionErrors(); // or get errors from
ValidatorForm#validate()
errors.add("errorName", new
ActionError("some.property.from.application.resources");
saveErrors(request, messages);


<html:errors property="errorName"/>
 
M

Murray

if (sPassword == null) {
return mapping.findForward("success");
} else {
// already exists
// display error message back to addUser.jsp
}
return mapping.findForward("addUser");

ActionErrors errors = new ActionErrors();
// or get errors from ValidatorForm#validate()
errors.add("errorName", new
ActionError("some.property.from.application.resources");
saveErrors(request, messages);


<html:errors property="errorName"/>
 
M

Murray

if (sPassword == null) {
return mapping.findForward("success");
} else {
// already exists
// display error message back to addUser.jsp
}
return mapping.findForward("addUser");

ActionErrors errors = new ActionErrors();
// or get errors from ValidatorForm#validate()
errors.add("errorName", new
ActionError("some.property.from.application.resources");
saveErrors(request, errors);


<html:errors property="errorName"/>
 
Joined
Oct 22, 2008
Messages
1
Reaction score
0
Murray said:

> if (sPassword == null) {
> return mapping.findForward("success");
> } else {
> // already exists
> // display error message back to addUser.jsp
> }
> return mapping.findForward("addUser");


ActionErrors errors = new ActionErrors();
// or get errors from ValidatorForm#validate()
errors.add("errorName", new
ActionError("some.property.from.application.resources");
saveErrors(request, errors);


<html:errors property="errorName"/>
Wow I was looking to do the same thing and found this 4 year old thread. I had just forgotten to call saveErrors(..) and was wondering what went wrong.

Thanks for the answer Murray.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top