Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Use of Velocity Generic Tools in a page decorator

Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2012

I am trying to use SortTool from Velocity Generic Tools inside a decorator that handles the search results.

The code is:

<div id="search-results-body">

            <ul class="search-results">

                #foreach($searchResult in $sorter.sort($results,
"lastModificationDate:desc"))


                 <li >
                    $action.newSearchResult($searchResult, $showExcerpts, $queryString)

                </li>

                #end

            </ul>

        </div>

Where $results is the collection of search results and $sorter is a handle to the Sorter class as explained in SortTool.

But the foreach loop is not executed since nothing is displayed, this is because $sort is null which means that confluence default velocity context don't know about that class.

How can I use those generic tools inside the decorators?

Thank you.

2 answers

1 accepted

3 votes
Answer accepted
Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2012

I found a solution in case someone need it:

1) install velocity-tools-generic-2.0.jar in confluence/WEB-INF/lib

2) Create a plugin in order to add $sorter to Confluence velocity context:

<atlassian-plugin name="Sorter" key="confluence.extra.sorter">

<plugin-info>
    <description>
      Plugin to do sorts in velocity templates and decorators.
    </description>
    <!-- This version is displayed in the application's Plugin Manager. -->
    <version>1.0</version>
  </plugin-info>

    <velocity-context-item key="mySorter"
          name="Sorter" context-key="sorter"
          class="org.apache.velocity.tools.generic.SortTool" />
</atlassian-plugin>

Now the search results are ordered descending. I would like to know if there is a cleaner way to do 2), since just doing 1) didn't do, nothing was shown.

leonizm June 22, 2012

Can't get sorttool class to load, please help.

Could not load class: org.apache.velocity.tools.generic.SortTool' to 'com.leonizm.confluence.plugins.testp'

Thanks,

Leon

1 vote
Andrey S October 22, 2012

I am summing: To use $sorter.sort($results,"lastModificationDate:desc"))

in velocity macros Confluense Admin->User Macros macros in confluense You should

1) install velocity-tools-generic-2.0.jar in confluence/WEB-INF/lib

2) Name xml above as "atlassian-plugin.xml" zip (the only file) it into .jar file (for example sorter.jar) and install it as a usual plugin using Confluense Admin->Plugins .

Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 2, 2013

Awesome, thanks for this!

Vijay Krishna B
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2015

Thanks Andrey.sorter.jar was working fine with confluence 4.3.Do I need to make changes in order to use the same jar in 5.6.5.After installation of sorter.jar in 5.6.5 it shows an error "This add-on could not be loaded. It has one or more errors that prevent it from being enabled. Refer to the logs for more information.". Can you please help regarding this.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events