Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Paul Franky
How to use Velocity in AJAX response
March 30, 2010 1:27 PM
Answer

Paul Franky

Rank: New Member

Posts: 8

Join Date: December 11, 2009

Recent Posts

Hi,

we've built a portlet that uses the serveResource() method (see JSR 286) for creating a response to an AJAX request. This works fine so far.

What we wanna do is to render a velocity template within this method directly to an object. This object we would like to return as a string (or bytes) in response to the AJAX request.

How could we do this? Will ThemeUtil.includeVM() be our friend?
Mazhar Anwar
RE: How to use Velocity for an AJAX response
March 30, 2010 7:33 AM
Answer

Mazhar Anwar

Rank: Regular Member

Posts: 125

Join Date: February 5, 2010

Recent Posts

Paul Franky:
Hi,

we've built a portlet that uses the serveResource() method (see JSR 286) for creating an response to an AJAX request. This works fine so far.

What we wanna do is to render a velocity template within this method directly to an object. This object we would like to return as a string (or bytes) in response to the AJAX request.

How could we do this? Will ThemeUtil.includeVM() be our friend?


If you use jsp rather than velocity, it will be more simple.
you can have some html tag (<div>, <span>, etc with some ids and if require you can make it hidden initially) and after executaion of your serveResource method you can set those html tags dynamically using java script(AJAX) based on your response.

This is something intresting and innovative, please reply if success emoticon
Hope This Help.

Regards,
Mazhar
Paul Franky
RE: How to use Velocity in AJAX response
March 30, 2010 1:26 PM
Answer

Paul Franky

Rank: New Member

Posts: 8

Join Date: December 11, 2009

Recent Posts

Very sorry, not to use Velocity is not an option. We use the spring MVC Framework and Velocity to clearly separate code and design. That's also the reason for not creating a document "by-hand" inside serveResource().

Prepared hidden content is also not an option because we need to update large data tables (and we wanna update only those).


Nevertheless thanks for thinking about it.