Fórum

resourceURL parameter issue

Michael Anthony Dorrian, modificado 12 Anos atrás.

resourceURL parameter issue

Junior Member Postagens: 98 Data de Entrada: 03/09/09 Postagens Recentes

<script type="text/javascript">
     function downloadTest()

        var csv_vals='"col1","col2","col3","col4","col5"<br>';
            for(var i=1;i<100;i++)
            {
            	csv_vals+='"1","2","3","4","5"<br>';
            }
            //alert(csv_value);
            //<portlet:namespace/>SetExcelData(csv_value);

            var url='<portlet:resourceURL><portlet:param name="table_data" value="test"/><portlet:param name="updateResource" value="DownloadCSV" /></portlet:resourceURL>';
            url += "&<portlet:namespace/>param1=" + encodeURI(csv_vals);
            location.href =url;
</script>   
Java Class
public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
String requestMethod=request.getParameter("param1");
}


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..
thumbnail
Sandeep Nair, modificado 12 Anos atrás.

RE: resourceURL parameter issue

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
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, modificado 12 Anos atrás.

RE: resourceURL parameter issue

Junior Member Postagens: 98 Data de Entrada: 03/09/09 Postagens Recentes
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...
thumbnail
amit doshi, modificado 12 Anos atrás.

RE: resourceURL parameter issue

Liferay Master Postagens: 550 Data de Entrada: 29/12/10 Postagens Recentes
Hi Michael,

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

<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">

function testingajax()
{

var csv_vals='"col1","col2","col3","col4","col5"<br>';
        for(var i=1;i<500;i++)
        {
            csv_vals+='"1","2","3","4","5"<br>';
        }
$.ajax(
        {
        	type: "POST",
              url: resourceurl , 
            data: 
            	{
            		 test : csv_vals
            	},
            
            success: function(response) 
            {
                alert(response);	
            }
});	
}
</script>



and in the JAVA Class

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


Please let me know if any concern.

Thanks & Regards,
Amit Doshi
thumbnail
Nagendra Kumar Busam, modificado 12 Anos atrás.

RE: resourceURL parameter issue

Liferay Master Postagens: 678 Data de Entrada: 07/07/09 Postagens Recentes
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, modificado 12 Anos atrás.

RE: resourceURL parameter issue

Junior Member Postagens: 98 Data de Entrada: 03/09/09 Postagens Recentes
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..
thumbnail
Nagendra Kumar Busam, modificado 12 Anos atrás.

RE: resourceURL parameter issue

Liferay Master Postagens: 678 Data de Entrada: 07/07/09 Postagens Recentes
Can you explain a bit more about the same
Michael Anthony Dorrian, modificado 12 Anos atrás.

RE: resourceURL parameter issue

Junior Member Postagens: 98 Data de Entrada: 03/09/09 Postagens Recentes
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...
thumbnail
Nagendra Kumar Busam, modificado 12 Anos atrás.

RE: resourceURL parameter issue

Liferay Master Postagens: 678 Data de Entrada: 07/07/09 Postagens Recentes
Good to know you resolved by yourself & thank you for sharing the approach