Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActionErrors and ActionMessages

Status
Not open for further replies.

burnayev

Programmer
Joined
Dec 5, 2005
Messages
1
Location
US
I'm trying to validate a sign in form with 2 fileds: email and password.

I'm using standard "required" and "email" validators to check the validity of the email. As far as I can tell from the debugger output all the errors are added under org.apache.struts.action.ERROR key like this:
org.apache.struts.action.ERROR={email=[errors.required]}

The email should exist in the database so there's a verification in SignInAction for that. If the email doesn't exist I add the respecitve ActionMessage
(as ActionError is deprecated):
ActionMessages errors = new ActionMessages();
errors.add("email", new ActionMessage("error.login.not.found"));
saveMessages(request, errors);

This guy is added under org.apache.struts.action.ACTION_MESSAGE key as follows:
org.apache.struts.action.ACTION_MESSAGE={email=[error.login.not.found[]]}

So, when I want to display both errors near my email input field I have to do this:

<!-- deprecated but short and sweet
html:errors property="email" header="errors.header.inline" footer="errors.footer.inline" prefix="errors.prefix.inline" suffix="errors.suffix.inline" /-->

<html:messages id="emailError" property="email">
<span class="error">
<bean:write name="emailError" />
&nbsp;
</span>
</html:messages>
<html:messages id="emailError2" property="email" message="true">
<span class="error">
<bean:write name="emailError2" />
&nbsp;
</span>
</html:messages>

It doesn't look quite efficient.

Here's a bunch of questions:
1. Am I missing a way of telling html:messages to pick up both errors and messages?
2. Am I missing a way of converting standard validation errors to messages so that they are added upder org.apache.struts.action.ACTION_MESSAGE and are picked up by html:messages with message="true"?
3. ValidatorForm.validate returns ActionErrors and is not deprecated. I don't get it. Can someone enlighten me on that?

I'm on Struts 1.2.8.

Thanks,
Borys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top