Search code examples
jqueryliferayliferay-6alloy-uiliferay-aui

How to execute renderURL in aui script or javascript in Liferay


I have come across a scenario where I am required to use renderURL in javascript. I have a aui-datatable with many rows of data. Upon clicking of any row, I need to call a render URL to load the next view.

Generally, I used to make use of renderURL in case of buttons by writing the renderURL in the onClick event. i.e,

aui:button name="TestButton" onClick="<%=testRenderURL.toString()%>"

But in the current scenario, the control will be in the delegate function of my datatable i.e, click handler function which is:-

Y.delegate('click', function(e) {
var target = e.currentTarget;
record = this.get('recordset').getRecord(target.get('id')).getValue();
alert(record.name);
  //HERE I NEED TO CALL RENDER URL AND LOAD NEXT JSP PAGE
  // after fetching current row values. i.e, send record.name to next jsp file
}, '#myTable', 'tr', dt); 

Solution

  •     AUI().use('liferay-portlet-url', function(A) {
          var url=Liferay.PortletURL.createRenderURL();
          url.setPortletId('currentPortletId');
          url.setParameter('name','value');
          A.one(document.createElement('a')).attr('href',url).simulate('click');
       })
    

    The code above would be helpful to you to achieve your requirement. Put it in click event handler function of row of your data-table.

    NOTE: Just replace currentPortletId, name and value in above code as per your requirement, you may also load 'liferay-portlet-url' module separately.