论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
master slave
serveResource called instead of actions
2013年5月2日 下午1:51
答复

master slave

等级: Junior Member

帖子: 30

加入日期: 2013年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
master slave
RE: can't submit form because of jQuery.Ajax and serveResource method
2013年5月2日 下午1:30
答复

master slave

等级: Junior Member

帖子: 30

加入日期: 2013年4月8日

最近的帖子

No idea !!
Apoorva Prakash
RE: serveResource called instead of actions
2013年5月2日 下午10:55
答复

Apoorva Prakash

等级: Liferay Master

帖子: 659

加入日期: 2010年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
master slave
RE: serveResource called instead of actions
2013年5月3日 上午2:06
答复

master slave

等级: Junior Member

帖子: 30

加入日期: 2013年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.
Tejas patel
RE: serveResource called instead of actions
2013年5月3日 上午3:15
答复

Tejas patel

等级: Junior Member

帖子: 71

加入日期: 2012年1月23日

最近的帖子

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
2013年5月3日 上午3:24
答复

master slave

等级: Junior Member

帖子: 30

加入日期: 2013年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).
Tejas patel
RE: serveResource called instead of actions
2013年5月3日 上午3:41
答复

Tejas patel

等级: Junior Member

帖子: 71

加入日期: 2012年1月23日

最近的帖子

Please add your code or share the zip file of your project over here.
master slave
RE: serveResource called instead of actions
2013年5月3日 上午6:39
答复

master slave

等级: Junior Member

帖子: 30

加入日期: 2013年4月8日

最近的帖子

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
2013年5月7日 上午6:48
答复

Tejas patel

等级: Junior Member

帖子: 71

加入日期: 2012年1月23日

最近的帖子

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
2013年5月7日 上午8:17
答复

master slave

等级: Junior Member

帖子: 30

加入日期: 2013年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 .
Tejas patel
RE: serveResource called instead of actions
2013年5月7日 下午10:29
答复

Tejas patel

等级: Junior Member

帖子: 71

加入日期: 2012年1月23日

最近的帖子

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
2013年5月9日 下午1:45
答复

master slave

等级: Junior Member

帖子: 30

加入日期: 2013年4月8日

最近的帖子

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