I have a hyperlink like this:
<a href="#" onclick="Liferay.Portlet.refresh('#p_p_id_myPortletName_')">link_name</a>
It works good, my portlet is being refreshed, but I also need to pass other variables (parameters) along with portlet id to refresh with based on passed params.
How can I do it?
You can create render url and make ajax call to reload portlet content.
In view.jsp:
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<liferay-portlet:renderURL var="reloadPortletURL" copyCurrentRenderParameters="true" portletMode="<%=LiferayPortletMode.VIEW.toString() %>"
windowState="<%=LiferayWindowState.NORMAL.toString()%>">
<liferay-portlet:param name="param1" value="Param1"/>
<liferay-portlet:param name="param2" value="Param2"/>
</liferay-portlet:renderURL>
<a href="#" onclick="ajaxCall('${reloadPortletURL}')">Reload portlet</a>
And js function:
function ajaxCall(url){
$.ajax({
type: 'GET',
url: url,
success: function(data) {
$('#p_p_id_myPortletName_').html(data);
}
});
}
Liferay.Portlet.refresh(portlet, data)
method has two arguments. You can look at /ROOT/html/js/liferay/portlet.js
for refresh method implementation.
portlet : It is portlet id
data : This object will be treated as form data when it send ajax request
function refreshPortlet(portletId, param1, param2){
var data = {'param1':param1,'param2':param2};
Liferay.Portlet.refresh(portletId, data);
}
A simple work-arround would be to create custom wrapper method to which you can pass additional parameters and achieve whatever your requirement is before calling to Liferay.Portlet.refresh
, as following:
function call:
<a href="#" onclick="refreshPortlet('#p_p_id_myPortletName_', 'param1', 'param2');">link_name</a>
function definition:
function refreshPortlet(portletId, param1, param2){
/* peform operations with other parameters here */
Liferay.Portlet.refresh(portletId);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.