RE: Liferay 7.2 - Set attribute on javascript

Fabio Carvalho, modified 6 Years ago. Junior Member Posts: 81 Join Date: 6/25/19 Recent Posts
Hi,

I have a custom portlet with another portlet embedded:
<%@ include file="/init.jsp" %>

<aui:select name="testId">
&nbsp;&nbsp; &nbsp;<aui:option value="100">Test 100</aui:option>
&nbsp;&nbsp; &nbsp;<aui:option value="200">Test 200</aui:option>
&nbsp;&nbsp; &nbsp;<aui:option value="300">Test 300</aui:option>
</aui:select>
<liferay-portlet:runtime portletName="Importer_INSTANCE_TEST" />

<aui:script>
&nbsp;&nbsp; &nbsp;AUI().ready('aui-dialog', 'node' , function(A) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;A.one("#<portlet:namespace />testId").on('change', function(e) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;    var data = {'param1': this.val()};
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Liferay.Portlet.refresh('#p_p_id_Importer_INSTANCE_TEST_', data);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;});
&nbsp;&nbsp; &nbsp;});
</aui:script>

What this is producing is: a simple select with 3 options, and when the user selects an option, the javascript is called and the embedded portlet is refreshed with the value of the selected option. Now, I want to get this value on my doView method of the refreshed portlet (Importer_INSTANCE_TEST). How should I do this?
Fabio Carvalho, modified 6 Years ago. Junior Member Posts: 81 Join Date: 6/25/19 Recent Posts
It seems that I can get the value on my doView method if I so something like this:
UploadPortletRequest test = PortalUtil.getUploadPortletRequest(renderRequest);
System.out.println(test.getParameter("param1"));

But doing like this I get the following WARN:
WARN &nbsp;[http-nio-8080-exec-10][UploadServletRequestImpl:242] Unable to parse upload request: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null

EDIT:
​​​​​​​
Ok, seems that doing like this, I can get the value without the warning:
HttpServletRequest test = PortalUtil.getHttpServletRequest(renderRequest);
test = PortalUtil.getOriginalServletRequest(test);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
System.out.println(test.getParameter("param1"));

Still not sure if this is the correct way to do this...
thumbnail
Mohammed Yasin, modified 5 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi,
You can get the parameter in doView either in two ways
 1. set  attribute with prefix portlet namespace   
var data = {'<portlet:namespace />param1': value}; 
then you can fetch using

ParamUtil.getString(renderRequest, "param1");
2. Without setting namespace you can fetch directly using HttpServletRequest 
var data = {'param1': value};

PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getParameter("param1")