留言板

Variables and methods in web content

Daniel Aschauer,修改在11 年前。

Variables and methods in web content

Junior Member 帖子: 39 加入日期: 12-10-22 最近的帖子
Hi!
I recently started evaluation liferay for the use in larger portal project, gone through the documentation, clicked around in the cms and did some portlet development tutorials.
Still I have some principle question on usage of the cms:
In some occasions I would need to include some dynamic content in a created web content, e.g. I need to call a method for currency convertion, get values from the database to include in the content.
Is there a possibility to do this?
Or to I have to write the content and functionality in a template?
Thanks,
Daniel
thumbnail
Pavel Savinov,修改在11 年前。

RE: Variables and methods in web content

Junior Member 帖子: 94 加入日期: 12-9-24 最近的帖子
Hi Daniel.

You can solve your task in 2 ways:

1) Use AJAX to call some remote service that will give you required info (exchange rates in your case)
2) Use Velocity to call some your local service that will provide the required info, like this:

 #set ($currencyLocalService = $serviceLocator.findService("com.daniel.service.CurrencyLocalService"))
 #set ($rate = $currencyLocalService.getExchangeRate(someDate, currencyAId, CurrencyBId))

And then use $rate variable.
Daniel Aschauer,修改在11 年前。

RE: Variables and methods in web content

Junior Member 帖子: 39 加入日期: 12-10-22 最近的帖子
Thanks.
Ok, that means this has to go to the template. To make it available to the editor I may use a PLACEHOLDER in the content and then replace it with the calculated value in the template?
I suppose I have access to request / session from the template to use user settings (language, role, and so on)..
thumbnail
Gaurav Jain,修改在11 年前。

RE: Variables and methods in web content

Regular Member 帖子: 145 加入日期: 11-1-31 最近的帖子
Daniel Aschauer:
Thanks.
Ok, that means this has to go to the template. To make it available to the editor I may use a PLACEHOLDER in the content and then replace it with the calculated value in the template?
I suppose I have access to request / session from the template to use user settings (language, role, and so on)..


Yes, web-content with structure/template is a kind of quite powerful tool in liferay that can be used for static/dynamic content.
However for security reasons request is not accesible as object in template but $request is in form of xmlRequest. [Refert o here]

You can check the liferay documentation on velocity objects here
Daniel Aschauer,修改在11 年前。

RE: Variables and methods in web content

Junior Member 帖子: 39 加入日期: 12-10-22 最近的帖子
Hi again!
What is the best way to provide a service that is accessible from within the template. Has that to be implemented as ext-plugin? Or can they be implemented in a portlet-plugin?
Didn't find any good documentation on this issue.
Daniel
thumbnail
Pavel Savinov,修改在11 年前。

RE: Variables and methods in web content

Junior Member 帖子: 94 加入日期: 12-9-24 最近的帖子
Hi Daniel.

It could be an ext-plugin (if you want to EXTend some existing Liferay portlet/service), a hook(if you want to override some functionality of Liferay service) or a plain portlet with service built with Service Builder.
The way depends only on your project's requirements.
Daniel Aschauer,修改在11 年前。

RE: Variables and methods in web content

Junior Member 帖子: 39 加入日期: 12-10-22 最近的帖子
As far as I understood the service builder is mainly used for generating and providing services related to DAOs.
So I guess if it just want to provide any other service I would build a service with using service builder or ext, as described http://www.devatwork.nl/2010/04/implementing-a-reusable-liferay-service-without-ext-or-service-builder/