burnayev wrote:
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[Email]]} 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: It doesn't look quite efficient. Here's a bunch of questions: 1. Am I miss
ing 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

When you do this:

  ActionMessages errors = new ActionMessages();
  errors.add("email", new ActionMessage("error.login.not.found"));
  saveMessages(request, errors);

you're storing a regular message, not an error message, which is why it's in a different place to the other validation errors. See below for the right way to do it:

> 1. Am I missing a way of telling html:messages to pick up both errors and messages?

You need to add your messages as errors rather than messages (i.e. you should be building an ActionErrors, not an ActionMessages). To get your errors and the errors from validator together, you need to add your messages to the ActionErrors created by validator, rather than create a new instance.

So, what you want is something more like

  ActionErrors errors = form.validate();
  // ... custom validation logic ...
  errors.add("email", new ActionMessage("error.login.not.found"));
  saveMessages(request, errors);

> 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"?

Nope; validation errors result in error messages not regular messages.

> 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.

ActionErrors represents a set of error messages. ActionMessages represents a set of non-error messages. Both types of message are now represented by the same class, ActionMessage. The deprecated class is ActionError (not ActionErrors), which is replaced by ActionMessage.

I know, a bit confusing, but hopefully that makes some sort of sense.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to