how can i call a specific method of the portlet.java class when calling ajax?
I think that we cannot have two different versions of the serveResource methods that we do for action methods, at least not with the default implementation.
If you need different methods, you will need Spring MVC ( @ResourceMapping ) to have this.
However, you can define different logic in your serveResource using resourceId as follows ( full example ):
In JSP:
<portlet:resourceURL var="myResourceURL" id="myResourceID01" />
In the portlet class, the serveResource will contain the following code:
String resourceID = request.getResourceID(); if(resoureID.equals("myResourceID01")) { // do myResourceID01 specific logic } else { // else do whatever you want }
Please keep in mind [Important]
In a portlet, you should not use the <html> , <head> , <body> tags, since portlets generate a fragment of the page, not the entire page. Even if this is allowed, your resulting page will not be well formed and will behave differently in different browsers. And besides, javascript that modifies the DOM element will be completely useless.
Edit after this comment :
You can also use ajax using action methods:
People use <portlet:actionURL> with ajax, usually for <form> - POST .
To do this, the actionURL generated a little differently in your jsp, like this:
<portlet:actionURL name="ajax_AddAdvertise" var="addToDo" windowState="<%= LiferayWindowState.EXCLUSIVE.toString()%>"> </portlet:actionURL>
And in your portlet you can have (as in the question):
@ProcessAction(name = "ajax_AddAdvertise") public void ajax_AddAdvertise(ActionRequest request, ActionResponse response) {