0

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

Community
  • 1
  • 1
BhavikKama
  • 8,566
  • 12
  • 94
  • 164
  • 1
    I dont know How it has added two question?i have tried first to add question but beacuse of network problem it wasnt showing ..so had added again.sorry for that – BhavikKama Nov 06 '12 at 13:48

1 Answers1

1

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.

Tejas Kanani
  • 133
  • 1
  • 2
  • 9
  • ya i want to use action url ??so can i call action url ?because i want to use difrent method on difrent button click on same page. – BhavikKama Nov 06 '12 at 09:52
  • Bhavik, instead of calling action url why don't you execute the code/logic which you have written in processAction which is going to be called when you execute any actionURL. – Tejas Kanani Nov 09 '12 at 08:57
  • ya had done with that...but if in case i wan to call that why i jsut asked – BhavikKama Nov 09 '12 at 11:14
  • No, there is an option to call specific method in action, if you add var="customMethod" to the tag. – Parkash Kumar Sep 17 '15 at 07:08