ActionErrors and ActionMessages
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Borys_Burnayev
Posted On:   Monday, December 5, 2005 02:39 PM

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"));    More>>

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

   <<Less

Re: ActionErrors and ActionMessages

Posted By:   alan_do  
Posted On:   Monday, December 5, 2005 05:05 PM

ActionErrors is NOT deprecated in struts 1.2 but is advised to be changed to ActionMessages for 'proper operation'. see release notes - http://struts.apache.org/struts-doc-1.2.7/userGuide/release-notes-1.2.4.html. Unfortunately, this means that (i believe) the ValidationForm.validate() must returns ActionErrors to ensure backward-compatibility so they are placed in the ACTION_ERROR key. with your login validation addition to ACTION_MESSAGE, you'll have to do both displays.


since you are using the validate() method, may as well use ActionErrors for everything else. otherwise, use declarative validation to validate your forms. with declarative validation, you have to use ActionMessage/s for everything (double check validator-rules.xml). beware that there is a slight learning curve for declarative validation.

About | Sitemap | Contact