You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "White, Tim" <Ti...@qwest.com> on 2009/09/17 22:58:39 UTC

Velocity Tools Error Question with Struts2

While my colleague is waiting to get added to this list, he asked me to post this question on his behalf.

He is trying to access the error info from a Struts2 controller, and is having the issues below:

Thanks,

Tim

I'm having trouble accessing the validationAware errors that are generated in an Action class.

GenericAction.java

declaration:
GenericLogin extends ActionSupport implements ServletRequestAware, ServletResponseAware, ServletContextAware, ValidationAware

Code:
  addFieldError("ERROR_MSG_HEADER", "/qCmsRepository/Global/Messages/Errors/error.errorMessageHeader.vm");
  addFieldError("FIELD_TEST", "/qCmsRepository/Global/Messages/Errors/error.systemFailure.vm");



Velocity Tool

TestErrorTool.java

declaration:
TestErrorToolextends ActionSupport implements ValidationAware

if (hasFieldErrors())
{
      Map errorMap = getFieldErrors();
      String cmsErrorMessagePath = "";
      List fieldErrorList = (List)errorMap.get(errorKey);
      Iterator errorIterator = fieldErrorList.iterator();
      while (errorIterator.hasNext())
      {
           cmsErrorMessagePath = (String)errorIterator.next();
           System.out.println("ErrorKey: " + errorKey);
           System.out.println("ErrorMessagePath: " + cmsErrorMessagePath);
       }
}

I cannot access the validationAware object when I get to the Velocity Tool.
When you examie hasFieldErrors() it returns false.  When I look at the objects in debug mode, the validationAware error, message & fieldErrors are NULL.

In the next step, the Interceptor, the validationAware objects are available again.

How do I get access to the ValidationAware objects that I set in the action class in the Velocity Tool?

Any help is appreciated.


Re: Velocity Tools Error Question with Struts2

Posted by Nathan Bubna <nb...@gmail.com>.
Personally, i'm really not sure.  I haven't used Struts 2, and last i
looked (which was easily a year ago) their VelocityTools support was
rather outdated.  Have you tried asking on the Struts list already?

Have you tried putting your object into the request attributes?

On Thu, Sep 17, 2009 at 1:58 PM, White, Tim <Ti...@qwest.com> wrote:
> While my colleague is waiting to get added to this list, he asked me to post this question on his behalf.
>
> He is trying to access the error info from a Struts2 controller, and is having the issues below:
>
> Thanks,
>
> Tim
>
> I'm having trouble accessing the validationAware errors that are generated in an Action class.
>
> GenericAction.java
>
> declaration:
> GenericLogin extends ActionSupport implements ServletRequestAware, ServletResponseAware, ServletContextAware, ValidationAware
>
> Code:
>  addFieldError("ERROR_MSG_HEADER", "/qCmsRepository/Global/Messages/Errors/error.errorMessageHeader.vm");
>  addFieldError("FIELD_TEST", "/qCmsRepository/Global/Messages/Errors/error.systemFailure.vm");
>
>
>
> Velocity Tool
>
> TestErrorTool.java
>
> declaration:
> TestErrorToolextends ActionSupport implements ValidationAware
>
> if (hasFieldErrors())
> {
>      Map errorMap = getFieldErrors();
>      String cmsErrorMessagePath = "";
>      List fieldErrorList = (List)errorMap.get(errorKey);
>      Iterator errorIterator = fieldErrorList.iterator();
>      while (errorIterator.hasNext())
>      {
>           cmsErrorMessagePath = (String)errorIterator.next();
>           System.out.println("ErrorKey: " + errorKey);
>           System.out.println("ErrorMessagePath: " + cmsErrorMessagePath);
>       }
> }
>
> I cannot access the validationAware object when I get to the Velocity Tool.
> When you examie hasFieldErrors() it returns false.  When I look at the objects in debug mode, the validationAware error, message & fieldErrors are NULL.
>
> In the next step, the Interceptor, the validationAware objects are available again.
>
> How do I get access to the ValidationAware objects that I set in the action class in the Velocity Tool?
>
> Any help is appreciated.
>
>

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