Possible Duplicate:
How to call specific method of portlet.java class rather then overide serveResource method?
I have one confusion about calling the ajax method in liferay right now am doing this way
This is my sample view.jsp in which am just calling one method of my portlet.java class
<%@ include file="/init.jsp"%>
<portlet:actionURL name="AddTest" var="add1" />
<portlet:resourceURL id="AddTest" var="AddTest"></portlet:resourceURL>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
function addToDo(addToDo){
var todo =document.getElementById('toDo').value;
$.ajax({
url :addToDo,
data: {"todo":todo,"CMD":"addToDo"},
type: "GET",
dataType: "text",
success: function(data) {
$("#toDoList").html(data);
}
});
}
</script>
</head>
<body>
<portlet:resourceURL var="addToDo" id="addToDo"></portlet:resourceURL>
<form>
<input type="text" name="toDo" id="toDo">
<button name="Add" type="button" onclick="addToDo('<%=addToDo%>')">Add</button>
<div id="toDoList">
</div>
</form>
</body>
</html>
now i have override serveResource method in my portlet.java class
@Override
public void serveResource(ResourceRequest request, ResourceResponse response){
if(request.getParameter("CMD").equals("addToDo")){
System.out.println("came here for add");
mediatype userToDo = new mediatypeImpl();
//userToDo.setMediaId(12345);
try {
userToDo.setPrimaryKey((CounterLocalServiceUtil.increment()));
userToDo.setMedianame(request.getParameter("todo"));
mediatypeLocalServiceUtil.addmediatype(userToDo);
}
catch (SystemException e) {
e.printStackTrace();
}
}
}
Now What i knew is from any Ajax call it will redirect to this method. but how can i call specific method of my porltet.java class from Ajax call?is there anyway? am just new bee in this Ajax and need help of you people..if anyone can guide me
how can i call specific method of my porltet.java class from Ajax call
Which specific method you are referring here ?
As when you execute any resourceURL it will call serverResource method only. Same as when you execute any actionURL, it will call processAction method only.