velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kishore Senji <kse...@gmail.com>
Subject Re: Accessing Validation Errors from Velocity
Date Thu, 05 Aug 2004 17:34:50 GMT
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 <paulh@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


Mime
View raw message