You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hi All,
I have 3 String lists(lets say ListA, ListB and ListC) in my java class which maps to velocity template. I need to display the values of the list in a table.
As velocity allows only foreach loop i can get values of only one list. is there a way to get values from all three lists?
If not in foreach loop, how to access the list values through its index?
Any inputs will be much appreciated.
Thanks
Hi,
with a little more investigation i found the answer.
from java class, lets say we have following code with populateVelocityParams method
params.put("listA",ListA); //Map the below java utils List class params.put("list",List.class);
then in velocity template,
just call
$listA.get(index); //"index" here is the list integer index position in ListA
Thanks,
Sharath TS
Velocity does not iterate Lists, as far as I can tell.
Velocity documentation says that it iterates over Vector, Hashtable, or an array (not a List).
In my experience, that is true.
https://velocity.apache.org/engine/1.7/user-guide.html#foreach-loop
https://velocity.apache.org/engine/2.1/user-guide.html#foreach-loop
I tried to make my velocity template iterate over a List and it did nothing. I converted my List to an array and it worked fine.
I know that this thread is really old but other, newer, threads point to it (that's how I found it) and this thread made me think I could iterate over a List. I could not.
I am developing a Confluence plugin, don't know if my pom.xml versions are out of date and some new Velocity engine or Atlassian ingredient changes things but beware: in my case, Velocity does NOT iterate over a List. It will, however iterate just fine over an array.
My template:
#foreach($result in $results)
<tr><td>${result}</tr></td>
#end
My getter in Java:
public String[] getResults() {
return results;
}
For my first try, using List<String> for my results the template rendered nothing for my List. I went with an array and it works. Decided not to mess with Vector for various reasons.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Recommended Learning For You
Level up your skills with Atlassian learning
Jira Align Program Essentials
Learn how to use Jira Align at the program level and how to plan for and manage your Program Increment (PI).
Managing Agile Boards and Reports
Learn how to pick the right board type for your team and customize it to fit your specific requirements.
Atlassian Certified Associate
Jira Software Board Configuration
Earn an associate-level credential from Atlassian that shows you can effectively configure Jira Software boards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.