You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Chris Pratt <th...@gmail.com> on 2007/12/28 20:19:52 UTC

Accessing ActionMessages from a Tag Library

OK, I'm losing my mind trying to figure this out.  I tried asking on
the Users list, but no one there seemed to know the answer, so I
figured I'd just ask the people who already know.

I'm trying to write a tag library that mimics the old Struts 1 html
tag library, I'm planning on open-sourcing it when I get close enough
to being done.  One of the tags I'm attempting to write is the old
<html:messages> tag.  But, I can't seem to figure out how to get hold
of the messages.  I tried to trace how it works in the new struts
<s:actionmessage> tag, but jumping between JSP Tag Libraries, OGNL
Processors, Components and FreeMarker scripts is too much for my
feeble brain.

What is required for a tag library to display the ActionMessage,
ActionErrors and FieldErrors ???

Any help would be greatly appreciated.
 (*Chris*)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Accessing ActionMessages from a Tag Library

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
  Pratt on 29/12/07 00:48, wrote:
> On Dec 28, 2007 4:15 PM, Adam Hardy <ah...@cyberspaceroad.com> wrote:
>> Well, I guess I should have read your whole message. :S
>>
>> Can you get hold of the Action in your tag? If so, then you can do this:
>>
>> ValidationAware validationAwareAction = (ValidationAware) action;
>> validationAwareAction.getActionErrors()
>> validationAwareAction.getActionMessages()
>> validationAwareAction.getFieldErrors()
>>
> That was my first thought as well, but unfortunately the flow is
> wrong.  Basically I would need to get hold of the previous action, not
> the current action.  It was the previous Action that had problems or
> messages to display to the user, and that's where things seem to break
> down.

Have a look at this thread:


http://www.nabble.com/How-to-redirect-error-message-to14238972.html



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Accessing ActionMessages from a Tag Library

Posted by Chris Pratt <th...@gmail.com>.
On Dec 28, 2007 4:48 PM, Chris Pratt <th...@gmail.com> wrote:
> On Dec 28, 2007 4:15 PM, Adam Hardy <ah...@cyberspaceroad.com> wrote:
> > Well, I guess I should have read your whole message. :S
> >
> > Can you get hold of the Action in your tag? If so, then you can do this:
> >
> > ValidationAware validationAwareAction = (ValidationAware) action;
> > validationAwareAction.getActionErrors()
> > validationAwareAction.getActionMessages()
> > validationAwareAction.getFieldErrors()
> >
> That was my first thought as well, but unfortunately the flow is
> wrong.  Basically I would need to get hold of the previous action, not
> the current action.  It was the previous Action that had problems or
> messages to display to the user, and that's where things seem to break
> down.
>   (*Chris*)
>

Apparently it helps if you're not completely stupid!!  After I wrote
that last reply I started thinking about the problem again and it
dawned on me that I was using a <result redirect="true">/</result>
which, obviously, was losing the messages.  What a moron.  It's
working exactly like you suggested.  Thanks for the sanity check.
  (*Chris*)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Accessing ActionMessages from a Tag Library

Posted by Chris Pratt <th...@gmail.com>.
On Dec 28, 2007 4:15 PM, Adam Hardy <ah...@cyberspaceroad.com> wrote:
> Well, I guess I should have read your whole message. :S
>
> Can you get hold of the Action in your tag? If so, then you can do this:
>
> ValidationAware validationAwareAction = (ValidationAware) action;
> validationAwareAction.getActionErrors()
> validationAwareAction.getActionMessages()
> validationAwareAction.getFieldErrors()
>
That was my first thought as well, but unfortunately the flow is
wrong.  Basically I would need to get hold of the previous action, not
the current action.  It was the previous Action that had problems or
messages to display to the user, and that's where things seem to break
down.
  (*Chris*)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Accessing ActionMessages from a Tag Library

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Well, I guess I should have read your whole message. :S

Can you get hold of the Action in your tag? If so, then you can do this:

ValidationAware validationAwareAction = (ValidationAware) action;
validationAwareAction.getActionErrors()
validationAwareAction.getActionMessages()
validationAwareAction.getFieldErrors()


Chris Pratt on 28/12/07 23:50, wrote:
> On Dec 28, 2007 3:42 PM, Adam Hardy <ah...@cyberspaceroad.com> wrote:
>> Here's one way, if you really don't want to use <fmt:message>
>>
>> import javax.servlet.jsp.jstl.fmt.LocaleSupport;
>>
>> LocaleSupport.getLocalizedMessage(pageContext, key);
>>
> 
> Please correct me if I'm wrong, but those get Localized messages from
> Resource Bundles, they don't display the ActionMessage, ActionErrors
> and FieldErrors from the Action, do they?
>   (*Chris*)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Accessing ActionMessages from a Tag Library

Posted by Chris Pratt <th...@gmail.com>.
On Dec 28, 2007 3:42 PM, Adam Hardy <ah...@cyberspaceroad.com> wrote:
> Here's one way, if you really don't want to use <fmt:message>
>
> import javax.servlet.jsp.jstl.fmt.LocaleSupport;
>
> LocaleSupport.getLocalizedMessage(pageContext, key);
>

Please correct me if I'm wrong, but those get Localized messages from
Resource Bundles, they don't display the ActionMessage, ActionErrors
and FieldErrors from the Action, do they?
  (*Chris*)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Accessing ActionMessages from a Tag Library

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Here's one way, if you really don't want to use <fmt:message>

import javax.servlet.jsp.jstl.fmt.LocaleSupport;

LocaleSupport.getLocalizedMessage(pageContext, key);



Chris Pratt on 28/12/07 19:19, wrote:
> OK, I'm losing my mind trying to figure this out.  I tried asking on
> the Users list, but no one there seemed to know the answer, so I
> figured I'd just ask the people who already know.
> 
> I'm trying to write a tag library that mimics the old Struts 1 html
> tag library, I'm planning on open-sourcing it when I get close enough
> to being done.  One of the tags I'm attempting to write is the old
> <html:messages> tag.  But, I can't seem to figure out how to get hold
> of the messages.  I tried to trace how it works in the new struts
> <s:actionmessage> tag, but jumping between JSP Tag Libraries, OGNL
> Processors, Components and FreeMarker scripts is too much for my
> feeble brain.
> 
> What is required for a tag library to display the ActionMessage,
> ActionErrors and FieldErrors ???
> 
> Any help would be greatly appreciated.
>  (*Chris*)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org