How to grab data sent by ui io fusion request in serveresource method?
Getting empty values for title and description in the serveResource method. Is it sending parameters from the io request correctly?
After entering blank values into the database, should I reload the page to see the inserted values? So the io request is not an ajax request?
<aui:script use="aui-base">
A.one('#<portlet:namespace/>save').on('click', function(event) {
var A = AUI();
var title=A.one('#<portlet:namespace/>title').val();
alert(title);
var description=A.one('#<portlet:namespace/>description');
var url = '<%= newJob.toString() %>';
A.io.request(
url,
{
method:'POST',
data: {
<portlet:namespace />title: title,
<portlet:namespace />description: description,
},
}
['aui-io-deprecated']
);
Liferay.Util.getOpener().<portlet:namespace/>closePopup('<portlet:namespace/>dialog');
});
source to share
AUI io request is just ajax request.
You can get the parameters in the serveResource method using the following code:
ParamUtil.get(resourceRequest, "NAMEOFPARAMETER");
Modify javascript function and provide data attribute as shown below:
data: {
'<portlet:namespace />title': title,
'<portlet:namespace />description': description,
}
source to share
I am assuming that title
and description
are text fields. If so, description
there is no challenge .val()
or, more appropriate .get('value')
. I haven't used dialog / modal in my source, but the general approach should be the same.
<script>
AUI().use('aui-base', 'aui-io-request', function(A){
A.one('#<portlet:namespace />save').on('click', function(event) {
var title= A.one('#<portlet:namespace />title').get('value');
var description=A.one('#<portlet:namespace />description').get('value');
var url = '<%=myResourceURL.toString()%>';
A.io.request(url,
{
method:'POST',
data: {
title: title,
description: description,
},
});
});
});
</script>
I am still relatively new to Liferay and I also had problems with this. I noticed that the options are data
not listed in parametersMap
the default ResourceRequest
as you said. Out of curiosity, I decided to use
UploadPortletRequest req = PortalUtil.getUploadPortletRequest(resourceRequest);
in the method serveResource
and check it out parametersMap
. The parameters title
and are available in it description
. I'm still researching where and how to access data from Liferay objects, but it would seem that in order to UploadPortletRequest
have data, it will burst out somewhere within the default limits ResourceRequest
... where I still remain elusive.
After entering blank values into the database, do I need to reload the page to see the inserted values?
You need to reload the page because the action resource
does not trigger a page refresh. If you are manipulating data that you want to be reflected in some other "view", you need to set up an appropriate link or use one of the other available URL types that triggers a method on doView
your other "view".
source to share