You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by pa...@webotech.co.uk on 2005/10/12 18:32:07 UTC
ActionMessages not displayed in the UI
user@struts.apache.org,
I have a validate() method on my form bean which returns ActionMessages, I
call the method from my action class. In my logs I can see that
ActionMessages have been populated and the flow is redirected to my error
page.
My validation method is:
public ActionMessages validate() {
ActionMessages errors = new ActionMessages();
errors.add("error", new ActionMessage("errors.required", "XXX"));
return errors;
}
I save the error generated in my validate() method using this in my action
class:
saveMessages(request, actionErrors);
At the top of my error page I have the following in my JSP:
<logic:messagesPresent>
<html:messages id="error">
<div class="ErrorMessage"><bean:write name="error" /><br /></div>
</html:messages>
</logic:messagesPresent>
Errors are displayed as I expect through my validation.xml but no error is
displayed when it goes through my action class. Any ideas why?
Thanks,
Paul
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OT] Re: ActionMessages not displayed in the UI
Posted by Dave Newton <ne...@pingsite.com>.
paul@webotech.co.uk wrote:
> I'm not so sure about using different style for front end and back end
> errors - great for a developer but confusing for a user (of a consumer
> site)
I display form errors within the form itself (with a non-radical message
saying they screwed up) and system errors in a nice red box: most system
errors require them to take specific action (eg, harass me) whereas
validation errors are something they need to deal with. That said, I've
also handled the same situation by forwarding to a separate page with
system error info (not on the form at all).
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ActionMessages not displayed in the UI
Posted by pa...@webotech.co.uk.
...
> system-oriented error types never run.
>
> Dave
>
When I was using an older version of Struts I used ActionErrors and I could
get away with just one set of jsp tags. I guess they have been deprecated
for a good reason.
Anyhow, when I get time I'll move the validation from my action class to a
custom struts validation since it is simple high level checks. I'm not so
sure about using different style for front end and back end errors - great
for a developer but confusing for a user (of a consumer site) but that
discussion shouldn't really be going on here...
Thanks again.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ActionMessages not displayed in the UI
Posted by Dave Newton <ne...@pingsite.com>.
paul@webotech.co.uk wrote:
> Thanks Dave that worked... my errors.jsp is pasted below. So I used
> two sets of tags one for the struts validation errors and one for the
> action errors. It would have been more elegant using only 1 set of
> tags but I guess this works just fine.
That's actually what I do to, but mostly because I use different styles
for system errors and validation errors and really want them displayed
in very different ways.
In general, I never have general system errors along with validation
errors. I create "extended" (non-validation.xml) validation errors by
using the deprecated ActionErrors stuff (I know, I know; I'm lazy...) If
there are validation errors then the stuff that can cause my more
system-oriented error types never run.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ActionMessages not displayed in the UI
Posted by pa...@webotech.co.uk.
Thanks Dave that worked... my errors.jsp is pasted below. So I used two sets
of tags one for the struts validation errors and one for the action errors.
It would have been more elegant using only 1 set of tags but I guess this
works just fine.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<html:xhtml/>
<%-- This deals with the struts validation errors --%>
<logic:messagesPresent>
<html:messages id="err">
<div class="ErrorMessage"><bean:write name="err" /><br /></div>
</html:messages>
</logic:messagesPresent>
<%-- This deals with the action errors --%>
<logic:messagesPresent message="true" property="error">
<html:messages message="true" id="err" name="error">
<div class="ErrorMessage"><bean:write name="err" /><br /></div>
</html:messages>
</logic:messagesPresent>
Dave Newton writes:
...
> Does this help?
>
> Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ActionMessages not displayed in the UI
Posted by Dave Newton <ne...@pingsite.com>.
paul@webotech.co.uk wrote:
> Errors are displayed as I expect through my validation.xml but no
> error is displayed when it goes through my action class. Any ideas why?
protected ActionForward errorToInput(final HttpServletRequest
request_, final ActionMapping mapping_, final String errorKey_, final
String msg_) {
log.error(msg_);
ActionMessages msgs = new ActionMessages();
msgs.add("action-errors", new ActionMessage(errorKey_, msg_));
saveMessages(request_, msgs);
return mapping_.getInputForward();
}
<logic:messagesPresent message="true" property="action-errors">
<div class="errorbox">
<html:messages message="true" id="err" name="action-errors">
<bean:write name="err"/>
<br/>
</html:messages>
</div>
</logic:messagesPresent>
Does this help?
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org