留言板

Unable to connect to Portlet class from AJAX request .

Ravi Kiran,修改在11 年前。

Unable to connect to Portlet class from AJAX request .

Junior Member 帖子: 98 加入日期: 11-12-12 最近的帖子
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,修改在11 年前。

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

Expert 帖子: 484 加入日期: 06-3-2 最近的帖子
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,修改在11 年前。

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

Liferay Master 帖子: 550 加入日期: 10-12-29 最近的帖子
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,修改在11 年前。

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

Junior Member 帖子: 98 加入日期: 11-12-12 最近的帖子
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,修改在11 年前。

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

Liferay Master 帖子: 550 加入日期: 10-12-29 最近的帖子
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,修改在11 年前。

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

Liferay Master 帖子: 550 加入日期: 10-12-29 最近的帖子
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,修改在11 年前。

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

Junior Member 帖子: 98 加入日期: 11-12-12 最近的帖子
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,修改在11 年前。

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

Regular Member 帖子: 106 加入日期: 07-10-3 最近的帖子
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,修改在11 年前。

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

Liferay Master 帖子: 550 加入日期: 10-12-29 最近的帖子
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,修改在9 年前。

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

New Member 帖子: 10 加入日期: 14-4-16 最近的帖子
Hi Doshi,

It is possible to make this call from portal theme?

Thanks in advance!