1
votes

I went through Liferay documentation and many other tutorials. But I am still struck with getting my requirement done.

This is what I need to achieve: 1.)Create new custom button or a link(href) in Wiki (built in) Portlet (anywhere in the portlet) 2.)On clicking of that button, I want to open a new jsp page in that portlet only.

This is What I did: I created a Liferay-hook project and selected /wiki/view.jsp to customize. Added a button by :

<liferay-ui:icon image="history" label="<%= true %>" message="Notify Users" method="get" url=<%="/c/portal/sample"%>" />

This is my liferay hook.xml:

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd"><hook><custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
<struts-action>
    <struts-action-path>/wiki/testing</struts-action-path>
    <struts-action-impl>
        com.liferay.sample.hook.action.WikiEmailHandlerAction
    </struts-action-impl>
</struts-action> <struts-action><struts-action-path>/portal/sample</struts-action-path><struts-action-impl>
    com.liferay.sample.hook.action.WikiEmailHandlerAction
</struts-action-impl>

Where, WikiEmailHandlerAction is my Java class which extends BaseStrutsPortletAction. When I click on the button "Notify Users", it is opening the new jsp page (but not inside the portlet but as a new page. Liferay Experts, Please let me know how to meet this requirement.

2

2 Answers

1
votes

Your jsp is opening into whole page is due to /c/portal/sample url.

You should create renderURL with some parameter set. And in Overridden StrutsAction class's render method check for that parameter and render your custom jsp.

Similarly go for action method, set some parameter in actionURL and check that parameter in processAction of Overridden StrutsAction class.

1
votes

First of all, your liferay-hook.xml doesn't look proper. It should also have element which should point to the folder inside your hook where you've put customized view.jsp of Wiki portlet.

<custom-jsp-dir>/custom_jsps</custom-jsp-dir>

This folder should also contain the other JSP file that you want to open when clicking the button.

NOTE: In portlet environment, you can NOT open a jsp by simply hyper-linking its path. It will be served as stand-alone jsp by your web container. So you'll have to generate a PortletURL and from your Portlet/StrutsAction dispatch request to appropriate JSP.

So, in your view.jsp, you need to create a PortletURL using <portlet:renderURL> or <portlet:actionURL> tag (as Pankaj mentioned above) as per your requirement.

Or, another simpler solution (or hack rather) is to use JQuery.ajax and load the JSP's content using Ajax.