0
votes

i use jQuery.ajax to call this method in my portlet :

 serveResource(ResourceRequest request, ResourceResponse response) 

The problem is when i try to call any action(ActionRequest req,ActionResponse resp) or submit buttons,only serveResource is called .

To call serveResource i use in my jsp :

 <portlet:resourceURL  var="ajaxURL" >
        <portlet:param name="jsp" value="<%=request.getPathInfo()%>" />
 </portlet:resourceURL>

Why only and always this method is called when i call an other actions methods .

EDIT:

My Controller Code:

public class ConseillerPorlet extends MVCPortlet {

public void addConsultant(ActionRequest request,ActionResponse response){
    List<String> errors=new ArrayList<String>();
        ConseillerLocalServiceUtil.addConseiller(request, response);

            SessionErrors.add(request, "error-saving-consultant");
            }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    } 
@Override
     public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
    String jsp=ParamUtil.getString(request, "jsp");
    System.out.println("ServeResouce Called by "+jsp);
    if(jsp.equals("/html/view.jsp")){
        String s="";
        List<Classe> classes;
        long Id=ParamUtil.getLong(request, "id");
        try {
            classes=Utils.getListClasses(etablissementId);
            for(Classe classe : classes)
            {
            s=s+"<option  value='"+classe.getClasseId()+"'>"+classe.getNomClasse()+"</option>";
            }
        } catch (SystemException e) {
            e.printStackTrace();
        }   
                response.getWriter().write(s);//return options for my <select> that i get using ajax and jquery  
    }
}

}

Thanks for help

3
It would be useful to see the rest of your controller codeMark Chorley

3 Answers

4
votes

It is because you're creating a resource URL and doing so will always hit the serveResource method. If you would like to hit action method you'll need to create an action URL.

<portlet:actionURL name="updateSomething" var="updateSomethingURL" />

Then inside your portlet class you can define:

public void updateSomething(ActionRequest actionRequest, ActionResponse actionResponse)
    throws Exception {

    // Code goes here.
}

Note that the name attribute of <portlet:actionURL /> corresponds to the method name above if you're extending the Liferay MVCPortlet class.

0
votes

Agreed with @ rp solution... You can also try this -

liferay-portlet:actionURL name="updateSomething" var="updateSomethingURL"

HTH

0
votes

I had conflicts with id's because i used same javascript ajax function in two portlets without using
<portlet:namespace />