Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Riddhi Shah
Override processAction method of EditMessageAction class.
January 30, 2013 1:41 AM
Answer

Riddhi Shah

Rank: Junior Member

Posts: 25

Join Date: March 6, 2012

Recent Posts

Hi,

I have to override processAction method of EditMessageAction class using hook. In particular, i just need to do some logic before executing delete CMD.

I am successfully able to make this logic before Delete. But problem is EDIT cmd. After this changes, when i click on Edit , it throws error "Forward does not exist". Moreover, my configurations doesnot create problems for other cmd like subscribe, unsusbscribe, lock and unlock. They are working fine. Only Edit cmd is in problem.

Below are the configurations i have done.

1. In liferay-hook.xml
1
2<struts-action>
3    <struts-action-path>/message_boards/edit_message</struts-action-path>
4    <struts-action-impl>com.liferay.portlet.messageboards.action.CustomEditMessageAction</struts-action-impl>
5</struts-action>


2. New class CustomEditMessageAction
 1
 2public class CustomEditMessageAction extends BaseStrutsPortletAction {
 3    public void processAction(StrutsPortletAction originalStrutsPortletAction,
 4            PortletConfig portletConfig, ActionRequest actionRequest,
 5            ActionResponse actionResponse) throws Exception {
 6        String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
 7        if (cmd.equals(Constants.DELETE)) {
 8            System.out.println("in Process Action method");
 9            String sendMail = ParamUtil.getString(actionRequest, "sendMail");
10            if (sendMail.equals("true")) {
11                System.out.println("call send mail logic here...");
12                if (Validator.isNotNull(ParamUtil.getString(actionRequest,
13                        "redirect"))) {
14
15                    System.out.println("redirect:"
16                            + ParamUtil.getString(actionRequest, "redirect"));
17                    SessionMessages.add(actionRequest, "showMailDeleteMessage");
18                    actionResponse.sendRedirect(ParamUtil.getString(
19                            actionRequest, "redirect"));
20                }
21            } else {
22                originalStrutsPortletAction.processAction(
23                        originalStrutsPortletAction, portletConfig,
24                        actionRequest, actionResponse);
25            }
26        } else {
27            originalStrutsPortletAction.processAction(
28                    originalStrutsPortletAction, portletConfig, actionRequest,
29                    actionResponse);
30        }
31    }
32}

basically what i am doing above is, call the custom logic if CMD is delete else call the original processAction method for all other CMD. Please refer EditMessageAction.java -> processAction method for all other types of CMD it has.

Note: The functionality i wanted to achieve for delete is working, but because of this, Edit is not working. Even other options like subscribe, lock, unlock, works fine.