Febry Fairuz
Febry Fairuz

Reputation: 549

Liferay.PortletURL in JavaScript creates an URL with /c/portal/layout

I am using Liferay 6.2 CE. And I want to create a portlet URL with Javascript. Here's my code:

<aui:script use="liferay-util-window,liferay-portlet-url">
  var portletURL = Liferay.PortletURL.createRenderURL();
  portletURL.setParameter('action', 'detailCourse');
  portletURL.setParameter('id', 10);
  console.log("render = " + portletURL.toString());
</aui:script>

portletURL.toString() results in:

http://localhost:8080/c/portal/layout?p_l_id=29913&p_p_lifecycle=0&_undefined_action=detailCourse&_undefined_id=19

But it should look like this:

http://localhost:8080/group/backdoor/home?p_p_id=classlistbackdoor_WAR_classlistbackdoor100SNAPSHOT&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_classlistbackdoor_WAR_classlistbackdoor100SNAPSHOT_id=10&_classlistbackdoor_WAR_classlistbackdoor100SNAPSHOT_action=detailCourse

Any idea what is wrong?

Upvotes: 1

Views: 2128

Answers (1)

Tobias Liefke
Tobias Liefke

Reputation: 9022

According to Creating Portlet URLs in JavaScript this was changed in Liferay 6.2:

After the fix for the security issue, generating friendly portlet URLs via JavaScript is no longer possible.

But there is a solution given, which works (at least for JSPs):

var portletURL = Liferay.PortletURL.createURL(
   '<%= PortletURLFactoryUtil.create(request, 
          portletId, 
          themeDisplay.getPlid(), 
          PortletRequest.RENDER_PHASE) %>');

Upvotes: 1

Related Questions