Foros de discusión

Unable to connect to Portlet class from AJAX request .

Ravi Kiran, modificado hace 11 años.

Unable to connect to Portlet class from AJAX request .

Junior Member Mensajes: 98 Fecha de incorporación: 12/12/11 Mensajes recientes
Hi ,
I am using Liferay 6.1 CE for Portal Application development .
I am trying to Use Jquery with AJAX in my Portlet .
This is my JSP Page as shown :

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />

<script type="text/javascript">

$(document).ready(function(){

jQuery.ajax({
url:'<portlet:resourceURL id="ajax" ></portlet:resourceURL>',
data: {id:data},
type: 'POST',
datatype:'json',
success: function(respData) {
alert(respData);
}
});
});
</script>



This is my MVC Portlet class
public class ArrayPortlet extends MVCPortlet {

@Resource(name="ajax")
public void testAjax(
PortletConfig config, ResourceRequest request, ResourceResponse response)
throws Exception {


}
}


But i am unable to connect to my Java class .
Could somebody please help me . Thanks .
thumbnail
Raja Nagendra Kumar, modificado hace 11 años.

RE: Unable to connect to Portlet class from AJAX request .

Expert Mensajes: 484 Fecha de incorporación: 2/03/06 Mensajes recientes
Can try it as href
<a href='<portlet:resourceURL>
<portlet:param name="vehicleId" value="${vehicleInfo.pk}" />
</portlet:resourceURL>'

This could tell you if the issue with ajax call firing issue or server side configuration issue.

Regards,
Nagendra
thumbnail
Amit Doshi, modificado hace 11 años.

RE: Unable to connect to Portlet class from AJAX request .

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
Ravi Kiran:
Hi ,
I am using Liferay 6.1 CE for Portal Application development .
I am trying to Use Jquery with AJAX in my Portlet .
This is my JSP Page as shown :

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />

<script type="text/javascript">

$(document).ready(function(){

jQuery.ajax({
url:'<portlet:resourceURL id="ajax" ></portlet:resourceURL>',
data: {id:data},
type: 'POST',
datatype:'json',
success: function(respData) {
alert(respData);
}
});
});
</script>



This is my MVC Portlet class
public class ArrayPortlet extends MVCPortlet {

@Resource(name="ajax")
public void testAjax(
PortletConfig config, ResourceRequest request, ResourceResponse response)
throws Exception {


}
}


But i am unable to connect to my Java class .
Could somebody please help me . Thanks .


Hi Ravi,

According to my knowledge you can't use @Resource(name="ajax"). Because there are not parameter in TLD through which you can bind it to the controller.
You have to use the serveResource method only.
Ravi Kiran, modificado hace 11 años.

RE: Unable to connect to Portlet class from AJAX request .

Junior Member Mensajes: 98 Fecha de incorporación: 12/12/11 Mensajes recientes
I have removed the Annotation @Resource(name="ajax") , but i am unable to connect to the Java class from Ajax Request .

Could anybody please tell me how to connect to Java Portlet class from the Ajax Request .
thumbnail
Amit Doshi, modificado hace 11 años.

RE: Unable to connect to Portlet class from AJAX request .

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
Ravi Kiran:
I have removed the Annotation @Resource(name="ajax") , but i am unable to connect to the Java class from Ajax Request .

Could anybody please tell me how to connect to Java Portlet class from the Ajax Request .


And also make the method name as serveResource.
thumbnail
Amit Doshi, modificado hace 11 años.

RE: Unable to connect to Portlet class from AJAX request .

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
Add more on my own comment.

Make in Controller method as :-

@Override
public void serveResource(final ResourceRequest resourceRequest,
final ResourceResponse resourceResponse) throws IOException, PortletException
{

}

Thanks & Regards,
Amit Doshi
Ravi Kiran, modificado hace 11 años.

RE: Unable to connect to Portlet class from AJAX request .

Junior Member Mensajes: 98 Fecha de incorporación: 12/12/11 Mensajes recientes
I tried the following , but still i am unsuccessful .

This is my JSP Page :

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />

<portlet:actionURL name="User" var="UserURL"/>

<script type="text/javascript">

$(document).ready(function(){

jQuery.ajax({
url:'<portlet:resourceURL id="resourceURL" var="resourceURL" />',
data: {id:data},
type: 'POST',
datatype:'json',
success: function(respData) {
alert(respData);
}

});

});
</script>A

This is under Java :


package com;

import java.io.IOException;

import javax.portlet.PortletException;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import com.liferay.util.bridges.mvc.MVCPortlet;

public class Test extends MVCPortlet {



@Override
public void serveResource(final ResourceRequest resourceRequest,
final ResourceResponse resourceResponse) throws IOException, PortletException
{

System.out.println("Hi Madahava Rao");
}
}



Am i doing anythig wrong ??
thumbnail
Zankar Shah, modificado hace 11 años.

RE: Unable to connect to Portlet class from AJAX request .

Regular Member Mensajes: 106 Fecha de incorporación: 3/10/07 Mensajes recientes
Hello
Possibly the way you are passing url, that could be an issue.

I just tried to do the same and it works perfectly for me

My jsp:
"
<portlet:resourceURL id="postURL" var="postURL">
<portlet:param name="protocol" value="http"></portlet:param>
</portlet:resourceURL>


<input type='hidden' id='postURL' value='${postURL}'/>

"

My js:
"
function accessHttp(){
var ajaxData = {
inputURL : $("#httpURLInput").val()
};

var url = $("#postURL").val();
alert(url);
$.ajax({
url: url,
data: ajaxData
}).done(function() {
alert("done");
});
}

"

My Java:


public class ContentUploaderPortlet extends MVCPortlet{

@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException,PortletException{
System.out.println("in hererererere");
String protocol = request.getParameter("protocol");
String url = request.getParameter("inputURL");
System.out.println("protocol is "+protocol+"---"+url);
}

}

thumbnail
Amit Doshi, modificado hace 11 años.

RE: Unable to connect to Portlet class from AJAX request .

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
Hi Ravi,

I checked implementing your code in my Project.

I found the problem is in your JAVAScript code that you had written. I now modified your code as below :-


<script type="text/javascript">

$(document).ready(function(){

$.ajax({                                       
url:'<portlet:resourceURL />',
data: {id:"f"},
type: 'POST',
datatype:'json',
success: function(respData) {
alert(respData);
}

});

});
</script>


The problem in your code is as below :-
1) use $ instead of jQuery in your ajax call.
2) data: {id:data}, you can't use data inside id, it's reserved word so. make it as data: {id:"f"}

Hope now it will solve your problem.

Thanks & Regards,
Amit Doshi
Lucian Alexandrescu, modificado hace 9 años.

RE: Unable to connect to Portlet class from AJAX request .

New Member Mensajes: 10 Fecha de incorporación: 16/04/14 Mensajes recientes
Hi Doshi,

It is possible to make this call from portal theme?

Thanks in advance!