Meaningless Drivel is fun!*
The moose likes Struts and the fly likes STRUTS2: Help.. <s:actionerror/> has stopped working and I have no idea why Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "STRUTS2: Help.. <s:actionerror/> has stopped working and I have no idea why" Watch "STRUTS2: Help.. <s:actionerror/> has stopped working and I have no idea why" New topic
Author

STRUTS2: Help.. <s:actionerror/> has stopped working and I have no idea why

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Hi,

I had an action class calling addActionError() and returning to a page with <s:actionerror/> in it and the message was being displayed fine, 2 months worth of develoment later and it seems to be broked. The specific code has not changed so I think this might be configuration.

I have a suspicion that this might be down to a change in my interceptor stack but there is nothing in the struts2 docs to say that there needs to be an interceptor there and after a couple of hours of trying different stacks nothing has changed, this is my stack anyway..



IS there some setting in struts2 that has to be set to make the actionerror messages return?

Thanks for any help in advance.

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
After plugging back in the default stack and finding it not to work i'm sure it is not the interceptors now.

I now think that the problem started when I moved my JSPs under the WEB-INF directory rather than just sitting in the root of the context.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Without knowing more it's hard to say, although most applications require several more interceptors than you have shown here.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
I'm debugging through the struts code just now.

The page calls multiple actions so i think that the errors that I add for that specific Action are not being found by the ActionErrorTag.

It looks like I have to assign the actionerror tag with the form in some way.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The page calls several actions? You mean like via the <s:action> tag?

If so, there's always a potential for issues--as far as I'm concerned the <s:action> tag invariable causes more problems than it solves, particularly when nested.

That aside, action errors are stored in the action itself (more or less, at least if you're extending ActionSupport). As you noted the the mechanism doesn't rely on any interceptors. I find it unlikely that the location of the JSP files makes a difference.

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Ahhh, got it now.

The tag that sets the error is the UserAction, but the result from that is to do a redirectAction onto a RegionAction.

So when the page finds the <s:actionerror/> it looks on the stack and the UserAction is gone, it only contains the RegionAction and friends.

I would have thought it would have handled that.

Now i'll have to find a way to fix it. Wonder if another type of result type will deal with it?

Obvious now but it took a few hours debugging to work it out.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Any time you use a redirect you're obviously going to lose everything on the current stack; the "store" interceptor exists for this reason. IIRC there's also a flash-style interceptor (maybe on google code?) that simplifies the configuration of "store".
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
I will have a look at the store interceptor.

Thanks
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Thanks a lot, that worked.

I never picked that interceptor up as I was using..

http://struts.apache.org/2.1.6/docs/interceptors.html

..as the docs and that page does not mention it.

Cheers
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It's actually listed in the "Framework Interceptors" about 2/3 of the way down; its description read:

Store and retrieve action messages / errors / field errors for action that implements ValidationAware interface into session.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: STRUTS2: Help.. <s:actionerror/> has stopped working and I have no idea why
 
Similar Threads
struts2 login interceptor not finding session attribute of user details.
struts2: what kicks in first- the interceptors or the form's validation?
Struts 2: Custom display of error messages
Confused with Built in Inerceptors in Struts2
struts2 + interceptor