Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
master slave
serveResource called instead of actions
May 2, 2013 1:51 PM
Answer

master slave

Rank: Junior Member

Posts: 30

Join Date: April 8, 2013

Recent Posts

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
master slave
RE: can't submit form because of jQuery.Ajax and serveResource method
May 2, 2013 1:30 PM
Answer

master slave

Rank: Junior Member

Posts: 30

Join Date: April 8, 2013

Recent Posts

No idea !!
Apoorva Prakash
RE: serveResource called instead of actions
May 2, 2013 10:55 PM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

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
master slave
RE: serveResource called instead of actions
May 3, 2013 2:06 AM
Answer

master slave

Rank: Junior Member

Posts: 30

Join Date: April 8, 2013

Recent Posts

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.
Tejas patel
RE: serveResource called instead of actions
May 3, 2013 3:15 AM
Answer

Tejas patel

Rank: Junior Member

Posts: 71

Join Date: January 23, 2012

Recent Posts

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.
master slave
RE: serveResource called instead of actions
May 3, 2013 3:24 AM
Answer

master slave

Rank: Junior Member

Posts: 30

Join Date: April 8, 2013

Recent Posts

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).
Tejas patel
RE: serveResource called instead of actions
May 3, 2013 3:41 AM
Answer

Tejas patel

Rank: Junior Member

Posts: 71

Join Date: January 23, 2012

Recent Posts

Please add your code or share the zip file of your project over here.
master slave
RE: serveResource called instead of actions
May 3, 2013 6:39 AM
Answer

master slave

Rank: Junior Member

Posts: 30

Join Date: April 8, 2013

Recent Posts

Tejas patel:
Please add your code or share the zip file of your project over here.

My Controller Code:
 1
 2
 3public class ConseillerPorlet extends MVCPortlet {
 4
 5public void addConsultant(ActionRequest request,ActionResponse response){
 6    List<String> errors=new ArrayList<String>();
 7        ConseillerLocalServiceUtil.addConseiller(request, response);
 8
 9            SessionErrors.add(request, "error-saving-consultant");
10            }
11    } catch (Exception e) {
12        // TODO Auto-generated catch block
13        e.printStackTrace();
14    }
15    }
16@Override
17     public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
18    String jsp=ParamUtil.getString(request, "jsp");
19    System.out.println("ServeResouce Called by "+jsp);
20    if(jsp.equals("/html/view.jsp")){
21        String s="";
22        List<Classe> classes;
23        long Id=ParamUtil.getLong(request, "id");
24        try {
25            classes=Utils.getListClasses(etablissementId);
26            for(Classe classe : classes)
27            {
28            s=s+"<option  value='"+classe.getClasseId()+"'>"+classe.getNomClasse()+"</option>";
29            }
30        } catch (SystemException e) {
31            e.printStackTrace();
32        }   
33                response.getWriter().write(s);//return options for my <select> that i get using ajax and jquery 
34    }
35}


In JSP:
1<portlet:resourceURL  var="ajaxURL" >
2    <portlet:param name="jsp" value="<%=request.getPathInfo()%>" />
3</portlet:resourceURL>
4
5and in submit form:
6<portlet:actionURL var="addConsultantURL" name="addConsultant" />
7<aui:form name="fm" action="<%=addConsultantURL.toString()%>" method="post">
8<aui:button type="submit" value="Valider" onClick="<%= addConsultantURL.toString()%>" name="saveConsultant" />

JS code :

 1
 2    function submitForm(){
 3        jQuery.ajax({
 4        type: 'POST',
 5        data:{
 6             id:jQuery('#etab').val()
 7        },
 8        url: "<%=ajaxURL%>",
 9        success: function(data){
10        jQuery("#classe").html(data);
11        }
12        });
13        }       
Tejas patel
RE: serveResource called instead of actions
May 7, 2013 6:48 AM
Answer

Tejas patel

Rank: Junior Member

Posts: 71

Join Date: January 23, 2012

Recent Posts

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.
master slave
RE: serveResource called instead of actions
May 7, 2013 8:17 AM
Answer

master slave

Rank: Junior Member

Posts: 30

Join Date: April 8, 2013

Recent Posts

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 .
Tejas patel
RE: serveResource called instead of actions
May 7, 2013 10:29 PM
Answer

Tejas patel

Rank: Junior Member

Posts: 71

Join Date: January 23, 2012

Recent Posts

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?
master slave
RE: serveResource called instead of actions
May 9, 2013 1:45 PM
Answer

master slave

Rank: Junior Member

Posts: 30

Join Date: April 8, 2013

Recent Posts

that's what i have done to solve the problem,before i used id's without portlet namespace.