RajneeshKumar (15) [Avatar] Offline
#1
Hi All,
I am using spring-MVC 3/Jquery for portlet development on lifery. At page rander time portlets will not contain any data except that empty place-holder (a jsp with empty div) with loading effect. At the same time one ajax call will be activated from each portlet to fetch the server side data to display in the portlet. Data will be formed using CMS + some webservice/DB call and finally returned and fill to the portlet placeholder by Jquery. Also I have multiple views for each portlet depending on user preferences and role.
1Approach: To do all data computation/formation (CMS + ws/DB call+ html +css) in controller and append it in one stringbuffer and write it back depending on view required to be rander. (traditional one)
2Approach: create different jsps (each jsp will contain its specific CMS + ws/DB call+ html +css) for all type of views and depending upon user preferences return that jsp from ajax controller.

Problem with first approach is since I am returning complete view for a portlet so there will be lot of developer effort while creating string buffer.

Second approach I am not sure whether it works efficiently or not.

What would be bast how I will do it from spring I am new to JSON so can i use it in my case?
Anny suggestion !!
ashish.sarin (361) [Avatar] Offline
#2
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Regarding the first approach, why you're thinking of creating a String buffer, when you can simply use a JSP page. Get the data from all the data sources and web services and store the information in a request attribute and dispatch the request to a JSP page.

For an example look at ch12_ResourceServing project's (http://code.google.com/p/portletsinaction/downloads/list) serveResource method defined in BookCatalogPortlet class.

regards
ashish
RajneeshKumar (15) [Avatar] Offline
#3
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Thanks for suggestion !! But how to return send the data to jsp and return jsp to ajax call. Please provide some code snippet if possible.
RajneeshKumar (15) [Avatar] Offline
#4
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Hi ashish,

I see the code. But its in normal servlet. I am using spring mvc
How to use
getPortletContext().getRequestDispatcher(
response.encodeURL(Constants.PATH_TO_JSP_PAGE
+ "bookList.jsp")).include(request, response);
in spring controller?
RajneeshKumar (15) [Avatar] Offline
#5
Re: spring-MVC 3/Jquery using Ajax for portlet display data
one more thing, I am suspicious about window.onload = <portlet:namespace/>getRecentBook();
because I have 20 portlets which should must executes seperate ajax call at the same time. so window.onload for each portlet will be best way to execute ajax call in my case?
RajneeshKumar (15) [Avatar] Offline
#6
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Any suggestion? because I am not able to use getportletContext() in spring mvc example
RajneeshKumar (15) [Avatar] Offline
#7
Re: spring-MVC 3/Jquery using Ajax for portlet display data
I tried following way inside my Controller:

PortletRequestDispatcher dispatcher = request.getPortletSession().getPortletContext().getRequestDispatcher("/WEB-INF/jsp/test.jsp");
dispatcher.include(request, response);

Code compiles but does not work. It gives jsp parse error while ajax call
RajneeshKumar (15) [Avatar] Offline
#8
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Please help
how to return jsp from spring portlet MVC ??
RajneeshKumar (15) [Avatar] Offline
#9
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Done !! I got it. So simple return a modelAndView object rather than void. Spring will take care of rest smilie
te_or (4) [Avatar] Offline
#10
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Can you please give the full solution, we have the same problem
Thanks.
ashish.sarin (361) [Avatar] Offline
#11
Re: spring-MVC 3/Jquery using Ajax for portlet display data
You can check the Chapter 7 and 8 examples (http://code.google.com/p/portletsinaction/downloads/list) to see this.
te_or (4) [Avatar] Offline
#12
Re: spring-MVC 3/Jquery using Ajax for portlet display data
The example in Chapter 7, "Hello World" does not contain AJAX?
Is there an example for contains ajax with Spring??
ashish.sarin (361) [Avatar] Offline
#13
Re: spring-MVC 3/Jquery using Ajax for portlet display data
I have created a sample portlet that makes use of Spring Portlet MVC and Ajax. The example is a variant of ch12_SpringDateTime project.

Please download Spring Portlet MVC - Ajax example from here: http://code.google.com/p/portletsinaction/downloads/list

Let me know if you face any issues with the example.

regards
ashish
te_or (4) [Avatar] Offline
#14
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Thank you for your help, it was very useful and works great!
anishnagaraj (4) [Avatar] Offline
#15
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Hi Ashish,

this example works perfectly in bringing back the content from the controller..
But what if we need to pass a value from the jsp to the Controller..
Do u have an example for the same..? Please help..
hiworld75018 (1) [Avatar] Offline
#16
Re: spring-MVC 3/Jquery using Ajax for portlet display data
Thanks, ashish, for this very understandable code.

I'm trying to serve a POSTed form via ajax, my code get called, via:
@ResourceMapping(value="submittedForm")

But I can't get any posted data, either with:
- public ModelAndView processForm(@ModelAttribute("formName") MyForm command, ResourceRequest request, ResourceResponse response)
or:
- public ModelAndView processForm(ResourceRequest request, ResourceResponse response)

Precision: The form is dynamic, using input names like 'inputs[XXX]'.

Is there something wrong about posting via ajax to a portlet ? Or is it because the form is dynamic ?

Thanks for your time,
Philippe