0

我使用 jQuery.ajax 在我的 portlet 中调用此方法:

 serveResource(ResourceRequest request, ResourceResponse response) 

问题是当我尝试调用任何操作(ActionRequest req,ActionResponse resp)或提交按钮时,只调用了serveResource

要调用我在 jsp 中使用的 serveResource :

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

为什么只有并且总是在我调用其他操作方法时调用此方法。

编辑:

我的控制器代码:

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  
    }
}

}

感谢帮助

4

3 回答 3

4

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.

于 2013-05-03T00:06:42.803 回答
0

我与 id 有冲突,因为我在两个 portlet 中使用了相同的 javascript ajax 函数而没有使用
<portlet:namespace />

于 2013-05-14T11:59:23.380 回答
0

同意@rp 解决方案……你也可以试试这个——

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

高温高压

于 2013-05-14T05:29:54.047 回答