wood burning stoves 2.0*
The moose likes Struts and the fly likes struts 2: implement PreResultListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2: implement PreResultListener" Watch "struts 2: implement PreResultListener" New topic
Author

struts 2: implement PreResultListener

Jonathan Su
Greenhorn

Joined: Aug 23, 2007
Posts: 4
I am trying to have a interceptor called after the Action is executed.

In struts.xml I have

<interceptors>
<interceptor name="accessControl" class="org.kp.pharmacy.sdp.web.interceptor.MemberInquiryAccessControlInterceptor"/>
</interceptors>

<action name="launch" class="org.kp.pharmacy.sdp.web.action.MemberInquiryAction" >
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="accessControl"/>
<result name="success">jsp/MemberInquiry.jsp</result>
<result name="error">jsp/error.jsp</result>
</action>

The the interceptor is like this:
public class MemberInquiryAccessControlInterceptor implements PreResultListener{

public void beforeResult(ActionInvocation invocation, String result) {
MemberInquiryAction action = (MemberInquiryAction)invocation.getAction();
if (action.getMrnNumber() == null || action.getRegionCode() == null || action.isMultipleMember()) {
action.setMemberInquiryAccess(new MemberInquiryAccessBean());
action.getMemberInquiryAccess().setReadOnlyMode();
}
else {
action.setMemberInquiryAccess(new MemberInquiryAccessBean());
action.getMemberInquiryAccess().setEditMode();
}
return;
}
}

However this interceptor doesn't get called after the action. Could anybody tell me what I am missing?

Thanks,
Dmitriy Kuznetsov
Greenhorn

Joined: Feb 05, 2010
Posts: 5
It seems, that MemberInquiryAccessControlInterceptor must implement Interceptor(instead of PreResultListener) to be invoked.

And i couldn't find a way to attach PreResultListener to action through struts.xml directly. So, the thing is to implement Interceptor, which attaches PreResultListener to ActionInvocation. E.g:

http://struts.apache.org/2.x/docs/can-we-access-an-actions-result.html

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 2: implement PreResultListener