留言板

serveResource called instead of actions

Charaf faceofjock,修改在10 年前。

serveResource called instead of actions

Junior Member 帖子: 30 加入日期: 13-4-8 最近的帖子
i use jQuery.ajax to call serveResource(ResourceRequest request, ResourceResponse response) in my portlet .
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" />
Why only and always this method is called when i call an other actions methods .

Thanks for help
Charaf faceofjock,修改在10 年前。

RE: can't submit form because of jQuery.Ajax and serveResource method

Junior Member 帖子: 30 加入日期: 13-4-8 最近的帖子
No idea !!
thumbnail
Apoorva Prakash,修改在10 年前。

RE: serveResource called instead of actions

Liferay Master 帖子: 658 加入日期: 10-6-15 最近的帖子
Charaf faceofjock:
i use jQuery.ajax to call serveResource(ResourceRequest request, ResourceResponse response) in my portlet .
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" />
Why only and always this method is called when i call an other actions methods .

Thanks for help


Hello Charaf,

What URL you are using as action of the form? You should create actionURL for this purpose.

HTH.

Thanks and REgards,
Apoorva Prakash
Charaf faceofjock,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 30 加入日期: 13-4-8 最近的帖子
Yes i have defined an action :<portlet:actionURL var="addEleveURL" name="addEleve" />
and then , i submit the form <aui:form id="f" action="<%=addEleveURL.toString()%>" method="post"> using submitButton.
The addEleveURL is not called , only serveressource does.
also submit button of the login portlet and some links in menu are not working.
thumbnail
Tejas Patel,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 71 加入日期: 12-1-24 最近的帖子
HI Charaf,
Which process do you follow to do this?
Means have you use mvc or other for that?
If you using mvc method so you have to override the processAction method of MVCPortlet.

here you create <portlet:actionURL var="addEleveURL" name="addEleve" /> action url,
so you have to define addEleve(...) method for that not action(...) method.
Charaf faceofjock,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 30 加入日期: 13-4-8 最近的帖子
Yes i use Liferay's MVCPortlet and in it , i have a public void addEleve(ActionRequest request,ActionResponse response){//add Student code }
have you understood my problem ?The problem is that i can submit the form and call addEleve() only when i delete <portlet:resourceURL var="ajaxURL" />.
When i add <portlet:resourceURL var="ajaxURL" /> , submit button execute only ServereRessource.

I use ajax because i need to get options of a select according to a previous selected value ,and without reloading the page( Filtering).
thumbnail
Tejas Patel,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 71 加入日期: 12-1-24 最近的帖子
Please add your code or share the zip file of your project over here.
Charaf faceofjock,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 30 加入日期: 13-4-8 最近的帖子
Tejas patel:
Please add your code or share the zip file of your project over here.

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="&quot;+classe.getClasseId()+&quot;">"+classe.getNomClasse()+"</option>";
            }
        } catch (SystemException e) {
            e.printStackTrace();
        }   
                response.getWriter().write(s);//return options for my <select> that i get using ajax and jquery  
    }
}In JSP:
    


and in submit form:



JS code :
	function submitForm(){
		jQuery.ajax({
		type: 'POST',
		data:{
			 id:jQuery('#etab').val()
		},
		url: "&lt;%=ajaxURL%&gt;",
		success: function(data){
		jQuery("#classe").html(data);
		}
		});
		}		
</select></classe></string></string>
thumbnail
Tejas patel,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 71 加入日期: 12-1-24 最近的帖子
Hello Charaf,

No need to write onClick="xyz" when you give the url in action="xyz" in form.
May be this create issue, please remove it and check again and let me know if your issue is solved or not.
Charaf faceofjock,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 30 加入日期: 13-4-8 最近的帖子
it's the only solution that helped me to overpass this problem that day.
Now , I have made a lot of changes and ajax works well ,but i don't know what is the solution :p , may be i had problem with 2 portlets that use the same ajax function or may be i have id's with the same name in different portlets , i added <portlet:namespace/> in functions and id's .
thumbnail
Tejas patel,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 71 加入日期: 12-1-24 最近的帖子
i have id's with the same name in different portlets , i added <portlet:namespace/> in functions and id's .


If you use id's with "<portlet:namespace/>" then it's unique id's, so what's the problem?
Charaf faceofjock,修改在10 年前。

RE: serveResource called instead of actions

Junior Member 帖子: 30 加入日期: 13-4-8 最近的帖子
that's what i have done to solve the problem,before i used id's without portlet namespace.