0

I've got a Liferay 6 server, in a Tomcat server.

Thing is, I am editing one of my public pages (the welcome one), so the JavaScript is read from the admin console. It simply puts a script in the end of the page with whatever you want. This is working good, and I'm visualizing a popup in the corner of the page (typical popup for giving an opinion about the page).

Now that the popup is ready, I need a servlet to send the petitions from its formulary, but I don't know how to create a simple Java servlet in Liferay Server.

I guess I have to create it independently, and deploy it into the Tomcat, no? But, how do I deploy it, and how can I set the hook so it doesn't collide with Liferay's environment?

Thank you!

Zerok
  • 227
  • 4
  • 19

2 Answers2

1

You have to wrap your servlet with Liferay's PortalDelegateServlet - see Usage of PortalDelegateServlet in Liferay

Community
  • 1
  • 1
Jozef Chocholacek
  • 2,874
  • 2
  • 20
  • 25
0

I've never tried something like this but this answer seems a logically correct way to do that, but that's not the Liferay way to handle this situation.

That would be to use Struts Action Hooks to create a new action that would be globally reachable throughout your portal.

This type of Hook can be used to override core portal (e.g c/portal/login) and portlet struts actions (e.g /login/forgot_password), this actions for Liferay Portal are specified in a struts-config.xml file in its WEB-INF folder.To override an action:

  1. in liferay-hook.xml file of your hook plugin under docroot/WEB-INF, add a struts-action element within the hook element.
  2. Inside struts-action element, add struts-action-path that specifies the action path you’re overriding and struts-action-impl that specifies your custom action class.This looks like:

    <struts-action-path>/login/login</struts-action-path>
        <struts-action-impl>
        com.myhook.action.ExampleStrutsPortletAction
        </struts-action-impl>
    </struts-action>
    
  3. Create a Struts portlet action class that extends BaseStrutsPortletAction. An example of this class is:

    public class ExampleStrutsPortletAction extends BaseStrutsPortletAction {
    
            public void processAction(StrutsPortletAction originalStrutsPortletAction,
                    PortletConfig portletConfig, ActionRequest actionRequest,
                    ActionResponse actionResponse) throws Exception {
    
                System.out.println("Custom Struts Action");
    
                originalStrutsPortletAction.processAction(originalStrutsPortletAction,
                        portletConfig, actionRequest, actionResponse);
            }
    
        public String render(StrutsPortletAction originalStrutsPortletAction,
                PortletConfig portletConfig, RenderRequest renderRequest,
                RenderResponse renderResponse) throws Exception {
    
            System.out.println("Custom Struts Action");
    
            return originalStrutsPortletAction.render(null, portletConfig,
                    renderRequest, renderResponse);
        }
    }
    

    Calling the method being overridden, like originalStrutsPortletAction.processAction, is not obligatory but a best practice to keep the behavior from the Action unchanged in regards of Liferay Portal. This type of hook can be used to add new Struts Actions also, it's the same as modifying an existing action, in this case liferay-hook.xml would be:

    <struts-action>
        <struts-action-path>/my/custom/path</struts-action-path>
        <struts-action-impl>
        com.myhook.action.ExampleStrutsAction
        </struts-action-impl>
    </struts-action>
    
CL.
  • 173,858
  • 17
  • 217
  • 259
KlajdPaja
  • 959
  • 1
  • 8
  • 17