掲示板

Anyone Have Velocity Tools Working in Liferay 6?

12年前 に Brent Williams によって更新されました。

Anyone Have Velocity Tools Working in Liferay 6?

New Member 投稿: 8 参加年月日: 11/10/18 最新の投稿
Hi All,

I am trying to get Velocity Tools 2.0 working in Liferay 6 so I can access object such as the SortTool within my velocity templates, but just can't get it to work. Documentation is very sparse, but from what I have seen I can drop the velocity-tools-2.0.jar in the /lib directory of my server and place tools.xml in the web-inf directory and should be good to go, however whenever I try to access something basic such as:

$convert.toInteger('12.6')

it just prints the code and does not parse it. Anyone know where to get step-by-step instructions for deploying this with Liferay?

Thanks!,
Brent
thumbnail
12年前 に Samir Gami によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

Regular Member 投稿: 162 参加年月日: 11/02/04 最新の投稿
Brent, From where you are trying to access sortTool, Are you working with Theme or portlet ??
12年前 に Brent Williams によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

New Member 投稿: 8 参加年月日: 11/10/18 最新の投稿
I'm working in the Velocity template associated to the structure I'm using inside the web content portlet.
12年前 に Brent Williams によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

New Member 投稿: 8 参加年月日: 11/10/18 最新の投稿
Ok, we got it solved.....

First of all, we were looking at exactly how the $sortTool.sort() method works, thinking the foreach loop actually did the sorting when it actually returns a collection that you are iterating through:

#foreach ($obj in $sortTool.sort($objects, "fieldnametosorton")
Display data from the sorted list here like $obj.fieldname
#end

Secondly, since we were sorting on a child field (reference previous post) we had to first build an array of maps and then sort on that since the sort method can't seem to access the child field:

#set ($array = [])
#foreach ($obj in $objects)
#set ($void = $array.add( { "field1" : $obj.getData(), "childfield" : $obj.childfield.getData() } ) )
#end

Then you can sort properly:

#foreach ($obj in $sortTool.sort($array, "childfield")
<p>This is a line sorted on $obj.childfield</p>
#end

Hopefully that helps someone!
thumbnail
11年前 に sunil G によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

New Member 投稿: 6 参加年月日: 11/12/09 最新の投稿
Hi Brent,

Is there any quick guide to sort tool in liferay.

Thanks in advance,
sunil
thumbnail
11年前 に Nikhil Nishchal によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

Regular Member 投稿: 177 参加年月日: 12/06/22 最新の投稿
Hi,
Velocity markup provides $sortTool to sort any collection.
Example :
#set ($menuItems= [])
#set ($tmp = $menuItems.add({"title" : "item1", "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item2", "url" : "http://www.google.com"}))
#foreach ($item in $sortTool.sort($menuItems, 'title:asc'))
<a href="$item.url">$item.title</a><br>
#end
#foreach ($item in $sortTool.sort($menuItems, 'title:desc'))
<a href="$item.url">$item.title</a><br>
#end

Reference:
http://www.liferay.com/community/forums/-/message_boards/message/6162176
sortTool doc - http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/tools/generic/SortTool.html
thumbnail
11年前 に sunil G によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

New Member 投稿: 6 参加年月日: 11/12/09 最新の投稿
Thx nikil, it was really helpful..
thumbnail
11年前 に Nikhil Nishchal によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

Regular Member 投稿: 177 参加年月日: 12/06/22 最新の投稿
sunil G:
Thx nikil, it was really helpful..



You are welcome emoticon
thumbnail
12年前 に Amos Fong によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
Brent,

Some of the tools should already be available, see http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Journal+Template+(Velocity) (I think the tools are version 1.6 though)

try:

$sortTool

Adding more custom variables is as simple as dropping the jar and xml in. See this wiki:
http://www.liferay.com/community/wiki/-/wiki/Main/Custom+Velocity+Variables

btw, I don't see convert as a tool, try this (http://velocity.apache.org/tools/devel/generic/MathTool.html:
$mathTool.toInteger("12.6")
12年前 に Brent Williams によって更新されました。

RE: Anyone Have Velocity Tools Working in Liferay 6?

New Member 投稿: 8 参加年月日: 11/10/18 最新の投稿
I'm accessing sortTool in the Velocity Template for the generic web content portlet in liferay. Thank you the mathTool works and sortTool is iterating through my objects list but is not working. I'm following the docs here:

http://www.docjar.org/docs/api/org/apache/velocity/tools/generic/SortTool.html

but all that happens is the data is printed to the screen inside the foreach loop, so I'm not sure how to actually implement the sortTool and can't seem to find any actual examples.

BTW, my structure looks like this:

headline (text field, repeatable)
-- body (HTML text box) (child element)
-- order (Text field) (child element)

I'm grabbing the main content record and all of its siblings and calling the sort method.

The headline.order field is what I'm trying to sort on.

Thanks,
Brent