<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Liferay 7.2 - Call portlet method from javascript</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=114639058" />
  <subtitle>Liferay 7.2 - Call portlet method from javascript</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=114639058</id>
  <updated>2026-04-05T08:36:42Z</updated>
  <dc:date>2026-04-05T08:36:42Z</dc:date>
  <entry>
    <title>RE: Liferay 7.2 - Call portlet method from javascript</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114662923" />
    <author>
      <name>Fabio Carvalho</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114662923</id>
    <updated>2019-08-08T09:30:26Z</updated>
    <published>2019-08-08T09:30:26Z</published>
    <summary type="html">Hi Mohammed,&lt;br /&gt;&lt;br /&gt;Your method works! For future reference let me show what I did exactly. I added the ajax call to my function:&lt;br /&gt;&lt;blockquote&gt;&amp;lt;portlet:defineObjects /&amp;gt;&lt;br /&gt;&amp;lt;portlet:resourceURL var=&amp;#34;filterURL&amp;#34; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;input type=&amp;#34;text&amp;#34; id=&amp;#34;daterange&amp;#34; /&amp;gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;        $(function () {&lt;br /&gt;               $(&amp;#39;#daterange&amp;#39;).daterangepicker({&lt;br /&gt;                       startDate: moment().subtract(7, &amp;#34;days&amp;#34;),&lt;br /&gt;                       endDate: moment(),&lt;br /&gt;                       locale: {&lt;br /&gt;                               &amp;#34;format&amp;#34;: &amp;#34;DD/MM/YYYY&amp;#34;,&lt;br /&gt;                               &amp;#34;separator&amp;#34;: &amp;#34; - &amp;#34;&lt;br /&gt;                       },&lt;br /&gt;                }, function (start, end) {&lt;br /&gt;                        $.ajax({&lt;br /&gt;			        url : &amp;#39;${filterURL}&amp;#39;,&lt;br /&gt;				type : &amp;#39;POST&amp;#39;,&lt;br /&gt;				data : {&lt;br /&gt;					&amp;#34;&amp;lt;portlet:namespace/&amp;gt;start&amp;#34;: start.toString(),&lt;br /&gt;					&amp;#34;&amp;lt;portlet:namespace/&amp;gt;end&amp;#34;: end.toString()&lt;br /&gt;            	}&lt;br /&gt;			});&lt;br /&gt;                });&lt;br /&gt;    &lt;br /&gt;                $(&amp;#39;#daterange&amp;#39;).on(&amp;#39;apply.daterangepicker&amp;#39;)&lt;br /&gt;        });&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;And in my java class I added the serveResource method:&lt;br /&gt;&lt;blockquote&gt;@Override&lt;br /&gt;public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {	&lt;br /&gt;         System.out.println(ParamUtil.getString(request, &amp;#34;start&amp;#34;));&lt;br /&gt;	 super.serveResource(request, response);&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;</summary>
    <dc:creator>Fabio Carvalho</dc:creator>
    <dc:date>2019-08-08T09:30:26Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.2 - Call portlet method from javascript</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114645180" />
    <author>
      <name>Mohammed Yasin</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114645180</id>
    <updated>2019-08-07T16:35:28Z</updated>
    <published>2019-08-07T16:35:28Z</published>
    <summary type="html">Hi, &lt;br /&gt;  You can do ajax call to portlet from javscript to pass the data from javascript to Java class. &lt;br /&gt;&lt;br /&gt;  For this you can create a resource url , and call the  serveResource method of portlet or MVC Resource command.&lt;br /&gt;&lt;br /&gt;You can refer below link &lt;br /&gt;&lt;a href="https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/mvc-resource-command"&gt;https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/mvc-resource-command&lt;/a&gt;</summary>
    <dc:creator>Mohammed Yasin</dc:creator>
    <dc:date>2019-08-07T16:35:28Z</dc:date>
  </entry>
  <entry>
    <title>Liferay 7.2 - Call portlet method from javascript</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114639057" />
    <author>
      <name>Fabio Carvalho</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114639057</id>
    <updated>2019-08-07T15:07:46Z</updated>
    <published>2019-08-07T15:07:46Z</published>
    <summary type="html">Hi,&lt;br /&gt;&lt;br /&gt;I am trying the &lt;a href="http://www.daterangepicker.com/"&gt;date range picker&lt;/a&gt; and I have the following code in my view.jsp:&lt;br /&gt;&lt;blockquote&gt;&amp;lt;input type=&amp;#34;text&amp;#34; id=&amp;#34;daterange&amp;#34; /&amp;gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;        $(function () {&lt;br /&gt;                $(&amp;#39;#daterange&amp;#39;).daterangepicker({&lt;br /&gt;                        startDate: moment().subtract(7, &amp;#34;days&amp;#34;),&lt;br /&gt;                        endDate: moment(),&lt;br /&gt;                        locale: {&lt;br /&gt;                                &amp;#34;format&amp;#34;: &amp;#34;DD/MM/YYYY&amp;#34;,&lt;br /&gt;                                &amp;#34;separator&amp;#34;: &amp;#34; - &amp;#34;&lt;br /&gt;                        },&lt;br /&gt;                }, function (start, end) {&lt;br /&gt;                        alert(&amp;#34;New date range selected: &amp;#39;&amp;#34; + start + &amp;#34;&amp;#39; to &amp;#39;&amp;#34; + end + &amp;#34;&amp;#39;&amp;#34;);&lt;br /&gt;                });&lt;br /&gt;    &lt;br /&gt;                $(&amp;#39;#daterange&amp;#39;).on(&amp;#39;apply.daterangepicker&amp;#39;)&lt;br /&gt;        });&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/blockquote&gt;&lt;br /&gt;Until now its working ok! I reach the alert with the start and end values that I selected. Now I want to call and pass those values to a Java method that I have on my portlet:&lt;br /&gt;&lt;blockquote&gt;public void filterByDate(ActionRequest request, ActionResponse response) {&lt;br /&gt;        System.out.println(&amp;#34;SUCCESS&amp;#34;);&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;What would be the correct aproach for this?</summary>
    <dc:creator>Fabio Carvalho</dc:creator>
    <dc:date>2019-08-07T15:07:46Z</dc:date>
  </entry>
</feed>
