You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Paul Harrison <Pa...@chp.co.uk> on 2004/08/05 19:08:40 UTC

Accessing Validation Errors from Velocity

Hi,

I've just upgraded my project to Struts 1.2.1, which I am using with
Velocity 1.4 and VelocityStrutsLink 1.1.

Everything is fine, except for getting back Struts validator messages.

To pick up Struts generated validation messages I use:

#foreach( $error in $errors.getAll() )
<li>$error</li>
#end

which correctly shows the validation messages generated by the Struts
validator.

However when I want to place an error message on the session I can no
longer use ActionError as it has been deprecated, so I have changed to
ActionMessage.

Which means I have to use:

#foreach( $message in $messages.getAll() )
<li>$message</li>
#end

to pick it up, which also works correctly.

So I have to use $errors to pick up Struts generated validation errors
and $messages to pick up the error messages I have generated.

I've updated my validation-rules.xml file to 1.2.1 and have included all
the jars from Struts 1.2.1 in my project.

How can I get both the Struts validator messages and my own generated
messages to be accessible by one method (e.g. just $errors or just
$messages)? Are there newer versions of Velocity or the
VelocityStrutsLink tools I need to use?

Thanks,

Paul.


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Accessing Validation Errors from Velocity

Posted by Kishore Senji <ks...@gmail.com>.
To display both messages generated by Validator and you, add your
messages to the same ActionErrors instance generated by Validator.

So, in the validate() method of your ActionForm which extends
ValidatorForm, do something like the one below

public ActionErrors validate(
	ActionMapping mapping,
	HttpServletRequest request) {
	ActionErrors errors = super.validate(mapping, request);
	errors.add("myOwnMessage", new ActionMessage(...));
	return errors;
}

In the template, using your Errors Tool, all your messages get displayed.

Thanks,
Kishore Senji.

On Thu, 5 Aug 2004 18:08:40 +0100, Paul Harrison <pa...@chp.co.uk> wrote:
> Hi,
> 
> I've just upgraded my project to Struts 1.2.1, which I am using with
> Velocity 1.4 and VelocityStrutsLink 1.1.
> 
> Everything is fine, except for getting back Struts validator messages.
> 
> To pick up Struts generated validation messages I use:
> 
> #foreach( $error in $errors.getAll() )
> <li>$error</li>
> #end
> 
> which correctly shows the validation messages generated by the Struts
> validator.
> 
> However when I want to place an error message on the session I can no
> longer use ActionError as it has been deprecated, so I have changed to
> ActionMessage.
> 
> Which means I have to use:
> 
> #foreach( $message in $messages.getAll() )
> <li>$message</li>
> #end
> 
> to pick it up, which also works correctly.
> 
> So I have to use $errors to pick up Struts generated validation errors
> and $messages to pick up the error messages I have generated.
> 
> I've updated my validation-rules.xml file to 1.2.1 and have included all
> the jars from Struts 1.2.1 in my project.
> 
> How can I get both the Struts validator messages and my own generated
> messages to be accessible by one method (e.g. just $errors or just
> $messages)? Are there newer versions of Velocity or the
> VelocityStrutsLink tools I need to use?
> 
> Thanks,
> 
> Paul.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org