1
votes

I am trying to override "/blogs/view_entry" struts path. Following is the entry in liferay-hook.xml

<struts-action>
        <struts-action-path>/blogs/view_entry</struts-action-path>
        <struts-action-impl>com.smb.hook.action.BlogCustomEditAction</struts-action-impl>
</struts-action>

Whenever I click on any blog entry in Blogs portlet, It redirects to

http://localhost:8080/web/guest/home/-/blogs/test-blog-for-testing?_33_redirect=http%3A%2F%2Flocalhost%3A8080%2Fweb%2Fguest%2Fhome%3Fp_p_id%3D33%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_mode%3Dview%26p_p_col_id%3Dcolumn-2%26p_p_col_count%3D2

and blogs portlet becomes invisible.

At console, I can see the test print statement added in render method. After that following error message is logged:

ERROR [RuntimePageImpl-22][PortletRequestProcessor:466] Forward does not exist

Following are the methods overridden:

@Override
    public void processAction(StrutsPortletAction originalStrutsPortletAction,
            PortletConfig portletConfig, ActionRequest actionRequest,
            ActionResponse actionResponse) throws Exception {
        System.out.println("processAction :");
        super.processAction(originalStrutsPortletAction, portletConfig, actionRequest,
                actionResponse);
    }

    @Override
    public String render(StrutsPortletAction originalStrutsPortletAction,
            PortletConfig portletConfig, RenderRequest renderRequest,
            RenderResponse renderResponse) throws Exception {
        System.out.println("render :");
        return super.render(originalStrutsPortletAction, portletConfig, renderRequest,
                renderResponse);
    }

    @Override
    public void serveResource(StrutsPortletAction originalStrutsPortletAction,
            PortletConfig portletConfig, ResourceRequest resourceRequest,
            ResourceResponse resourceResponse) throws Exception {
        System.out.println("serveResource :");
        super.serveResource(originalStrutsPortletAction, portletConfig,
                resourceRequest, resourceResponse);
    }

I have tried passing null for originalStrutsPortletAction as shown in one of the example on liferay dev site but no change in output.

Any help on this is appreciated.

1

1 Answers

3
votes

I guess that you extend BaseStrutsPortletAction (not stated in your snippet).

The default methods of BaseStrutsPortletAction do not delegate to originalStrutsPortletAction - but they delegate to the methods of your class without the originalStrutsPortletAction, which are empty in default.

So you have to call originalStrutsPortletAction by yourself:

@Override
public void processAction(StrutsPortletAction originalStrutsPortletAction,
        PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {
    originalStrutsPortletAction.processAction(portletConfig, actionRequest, actionResponse);
}

@Override
public String render(StrutsPortletAction originalStrutsPortletAction,
        PortletConfig portletConfig, RenderRequest renderRequest,
        RenderResponse renderResponse) throws Exception {
    return originalStrutsPortletAction.render(portletConfig, renderRequest, renderResponse);
}

@Override
public void serveResource(StrutsPortletAction originalStrutsPortletAction,
        PortletConfig portletConfig, ResourceRequest resourceRequest,
        ResourceResponse resourceResponse) throws Exception {
    originalStrutsPortletAction.serveResource(portletConfig, resourceRequest, resourceResponse);
}