File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Velocity - Using Loops for Handling lists within variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Velocity - Using Loops for Handling lists within variables" Watch "Velocity - Using Loops for Handling lists within variables" New topic
Author

Velocity - Using Loops for Handling lists within variables

Roger Anderson
Greenhorn

Joined: Dec 29, 2012
Posts: 1
Hello All, I am having an issue with using loops on handling a results list variable if it has one or two results.

Here is what I am trying to accomplish.

I have a results list variable with two results:

Supplemental
2nd of result list text

Result
1st of result list text.
==========================================


If I have a results list variable with one result

Result
1st of result list text

===============================================

Based upon the code I have listed below, this works successfully when I have a variable with two results. However, if I only have one result, the label supplemental will display and no results show. This makes sense as the if statement is looking for anything to where the resultslist variable is greater or equal to 2. The issue I am having is that I can't seem to get this to work per the result of variable with one result. I tried an elseif statement, but the results end up getting duplicated.


<SPAN style="FONT-SIZE: 14pt">Supplemental</Span><BR>



#set ($a = 0)
#foreach ($results in $reportInfo.resultslist)
#set ($a = $a + 1)
#if ($a >= 2)
<BR>
<SPAN style="FONT-SIZE: 14pt">Result</Span>
<BR>
#end
<BR>
$resultslist
<BR>
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
You can access from the template the size() of the list and build a velocity condition using it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Velocity - Using Loops for Handling lists within variables