Thursday, August 30, 2012

Creating Portlet URLs(renderURL/actionURL/resourceURL) in Liferay through jsp and javascript


Here I am creating renderURL only.Other URL's can be created in the similar way

 In JSP :

<portlet:renderURL var="renderURL ">
    <portlet:param name="param-name" value="param-value" />
    <portlet:param name="param-name" value="param-value" />
</portlet:renderURL>


OR

 <%
           PortletURL renderURL = renderResponse.createRenderURL();
           renderURL.setParameter("param-name", "param-value");
           renderURL.setParameter("param-name", "param-value");
%>

In the above example param-name could be "jspPage" and param-value could be "/html/edit.jsp" if you want to navigate from current jsp page to some other jsp page (in this case edit.jsp) . We can set other parameters also as per our requirements.


Inside your javascript :

<script type="text/javascript">

function createRenderURL() {
    AUI().ready('liferay-portlet-url', function(A) {
        var renderURL = Liferay.PortletURL.createRenderURL();
        renderURL .setParameter("param-name","param-value");
        renderURL .setPortletId("your-unique-portlet-id");
        renderURL .setPortletMode("view");
        renderURL .setWindowState("normal");
        // i.e. your-unique-portlet-id can be like "helloworld_WAR_helloworldportlet"
    });
}
</script>

Note: Key point here is to set PortletId which is mandatory or else it would not be able to recognize the correct URL.


2 comments:

Buka said...
This comment has been removed by the author.
VARUSHI JAIN said...

I want to link two jsps. First is the view.jsp. On a button click on this page, a new jsp page functions.jsp should open. How do I do that?
Can you give me a step wise explanation of the same?