how to capture the data sent by alloy ui io request in serveresource method?

℡╲_俬逩灬. 提交于 2019-12-06 16:13:50

AUI's io request is ajax request only.

You can get parameters in serveResource method using code below:

ParamUtil.get(resourceRequest, "NAMEOFPARAMETER");

Modify your javascript function and provide data attribute as below:

 data: {
       '<portlet:namespace />title': title,
       '<portlet:namespace />description': description,
       }

I assume both title and description are textfields. If so, description is missing a .val() call, or more appropriately, .get('value'). I didn't use a dialog/modal in my source, but the overall 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'm still relatively new to Liferay and have had trouble with this as well. I've noticed that the data parameters are not in the parametersMap of the default ResourceRequest, as you have stated. Out of curiosity, I decided to use

UploadPortletRequest req = PortalUtil.getUploadPortletRequest(resourceRequest);

in the serveResource method and check it's parametersMap. The title and description parameters are available therein. I'm still learning where and how to access data from Liferay objects, but it would seem that for the UploadPortletRequest to have the data, it would be plucked from somewhere within the default ResourceRequest ... where still remains elusive to me.


After inserting blank values in database I have to reload the page to see the inserted values?

You have to reload the page because a resource action does not trigger a page refresh. If you are manipulating data that you want reflected in some other "view" you'll need to configure the appropriate communication or use one of the other available url types that does trigger the doView method of your other "view".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!