Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Michael Anthony Dorrian
resourceURL parameter issue
November 29, 2011 1:00 AM
Answer

Michael Anthony Dorrian

Rank: Junior Member

Posts: 89

Join Date: September 3, 2009

Recent Posts

 1
 2<script type="text/javascript">
 3     function downloadTest()
 4
 5        var csv_vals='"col1","col2","col3","col4","col5"<br>';
 6            for(var i=1;i<100;i++)
 7            {
 8                csv_vals+='"1","2","3","4","5"<br>';
 9            }
10            //alert(csv_value);
11            //<portlet:namespace/>SetExcelData(csv_value);
12
13            var url='<portlet:resourceURL><portlet:param name="table_data" value="test"/><portlet:param name="updateResource" value="DownloadCSV" /></portlet:resourceURL>';
14            url += "&<portlet:namespace/>param1=" + encodeURI(csv_vals);
15            location.href =url;
16</script>   
17Java Class
18public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
19String requestMethod=request.getParameter("param1");
20}


The above code works fine and my parameters are passed to the serverResource function but if i change the number of rows to 500 then it does not enter the serveresource function but a very long url is show in my browser....

I have tried to use encodeURIComponent instead of encodeURI but didnt work...I also tried without encoding the url but didnt work..tried encoding the whole url not just the parameters but did not work either...

How can i resolve this issueemoticon..
Sandeep Nair
RE: resourceURL parameter issue
November 29, 2011 2:04 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Can you try this url

var url='<portlet:resourceURL><portlet:param name="table_data" value="test"/><portlet:param name="updateResource" value="DownloadCSV" /><portlet:param name="param1" value="encodeURI(csv_vals)" /></portlet:resourceURL>';
location.href =url;

Regards,
Sandeep
Michael Anthony Dorrian
RE: resourceURL parameter issue
November 29, 2011 6:28 AM
Answer

Michael Anthony Dorrian

Rank: Junior Member

Posts: 89

Join Date: September 3, 2009

Recent Posts

Sandeep Nair:
Can you try this url

var url='<portlet:resourceURL><portlet:param name="table_data" value="test"/><portlet:param name="updateResource" value="DownloadCSV" /><portlet:param name="param1" value="encodeURI(csv_vals)" /></portlet:resourceURL>';
location.href =url;

Regards,
Sandeep


hi Sandeep,
Thanks for the reply but maybe you don't quite understand what i want.

The way you have described will pass the parameter param1 with a string value of encodeURI(csv_vals)...this csv value is a long javascript string which contains table row data that i want to export...it works fine with around 100 rows in the string but when the string gets too long it breaks...
Amit Doshi
RE: resourceURL parameter issue
November 30, 2011 3:57 AM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 544

Join Date: December 29, 2010

Recent Posts

Hi Michael,

Following is the code I used that worked for me .
In the jsp page put the following code

 1<script  src="js/jquery-1.5.1.min.js" type="text/javascript"  />
 2<script type="text/javascript">
 3
 4function testingajax()
 5{
 6
 7var csv_vals='"col1","col2","col3","col4","col5"<br>';
 8        for(var i=1;i<500;i++)
 9        {
10            csv_vals+='"1","2","3","4","5"<br>';
11        }
12$.ajax(
13        {
14            type: "POST",
15              url: resourceurl ,
16            data:
17                {
18                     test : csv_vals
19                },
20            
21            success: function(response)
22            {
23                alert(response);   
24            }
25});   
26}
27</script>


and in the JAVA Class

1public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
2String requestMethod=request.getParameter("test");
3}


Please let me know if any concern.

Thanks & Regards,
Amit Doshi
Nagendra Kumar Busam
RE: resourceURL parameter issue
November 30, 2011 4:23 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 637

Join Date: July 7, 2009

Recent Posts

That's right you need to pass those values as parameter of data attribute of ajax call (ajax request type should be POST - default request type is GET which will pass as query string).

Real world limit for URLs is about 2000 characters, check the below link for ref
http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url

Check this for more info - http://api.jquery.com/jQuery.ajax/
Michael Anthony Dorrian
RE: resourceURL parameter issue
November 30, 2011 7:18 PM
Answer

Michael Anthony Dorrian

Rank: Junior Member

Posts: 89

Join Date: September 3, 2009

Recent Posts

Nagendra Kumar Busam:
That's right you need to pass those values as parameter of data attribute of ajax call (ajax request type should be POST - default request type is GET which will pass as query string).

Real world limit for URLs is about 2000 characters, check the below link for ref
http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url

Check this for more info - http://api.jquery.com/jQuery.ajax/


There is no way I know of to get a true Ajax request to pop a save dialog box..thats why i dont use Ajax..
Nagendra Kumar Busam
RE: resourceURL parameter issue
November 30, 2011 11:39 PM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 637

Join Date: July 7, 2009

Recent Posts

Can you explain a bit more about the same
Michael Anthony Dorrian
RE: resourceURL parameter issue
December 2, 2011 8:25 PM
Answer

Michael Anthony Dorrian

Rank: Junior Member

Posts: 89

Join Date: September 3, 2009

Recent Posts

Nagendra Kumar Busam:
Can you explain a bit more about the same


Thanks for your concern.I guess I should have mentioned that i wanted to prompt the user with a download dialog box using a resourceURl created
in the serveresource function...an ajax response cannot do this i believe..
But anyway i have already resolved the issue by using a different method.
Basically I have a hidden form with a hidden field and i set the datatable row data to the hidden field text and submit the form which triggers
the serveresource action which then returns the url for the download link to the file...
Nagendra Kumar Busam
RE: resourceURL parameter issue
December 5, 2011 12:56 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 637

Join Date: July 7, 2009

Recent Posts

Good to know you resolved by yourself & thank you for sharing the approach