Displaying multiple rows from Map object into VM file.

Prashant Mali May 12, 2017

I am trying to implement a JIRA report module. For this I am making use of the AbstractReport class which has generateReportHtml() method.
I have the following data that is being passed from java class to vm file:
Map<String, Object> velocityParams = new HashMap<String, Object>();
...
velocityParams.put("issueKey", issueKey);
velocityParams.put("userName", userName);
velocityParams.put("updateDate", updatedDate);
velocityParams.put("fromIssueType", fromIssueType);
velocityParams.put("toIssueType", toIssueType);
return descriptor.getHtml("view", velocityParams);
I want to display all the data through vm file
But I am unable to display multiple rows using foreach loop
Thanks in advance

3 answers

0 votes
Sam Hall
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 12, 2017

Can you give a snippet of the velocity template code you are using to iterate over the map?

At a guess you probably need to do the foreach loop on the map's entrySet. Something like:

#foreach ($mapEntry in $velocityParams.entrySet())
<tr>
<td>$mapEntry.key</td> <td>$mapEntry.value</td>
</tr> #end

If this doesn't help or you don't get a better answer on here, consider posting your question in Atlassian's dedicated developer community: https://developer.atlassian.com/community/

That's the better place for dev related questions like this.

Edit: Fixed URL.

Pooja Singh May 12, 2017

 

This is the snippet we used for displaying single row in the vm file. But we are unable to display multiple rows using foreach loop.

<tr>
    <td> $issueKey</td>
    <td>$userName</td>
    <td>$updateDate</td>
    <td>$fromIssueType</td>
    <td>$toIssueType</td>
</tr>

 Thanks,

Pooja Singh.

Pooja Singh May 12, 2017

This is the snippit we used for displaying single row in the vm file. But we are unable to display multiple rows using foreach loop

<tr>
    <td> $issueKey</td>
    <td>$userName</td>
    <td>$updateDate</td>
    <td>$fromIssueType</td>
    <td>$toIssueType</td>
</tr>
 


 

Prashant Mali May 12, 2017

This is the snippit we used for displaying single row in the vm file. But we are unable to display multiple rows using foreach loop
<tr>
<td> $issueKey</td>
<td>$userName</td>
<td>$updateDate</td>
<td>$fromIssueType</td>
<td>$toIssueType</td>
</tr>

Prashant Mali May 12, 2017

Please reply on the same

Sam Hall
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 12, 2017

So you have a collection of issues from somwhere that you are want to loop over?

There are examples in this tutorial showing use of a for each loop in the vm template: https://developer.atlassian.com/jiradev/jira-platform/guides/projects/tutorial-creating-a-jira-report

For example, you can find this snippet in the tutorial:

#foreach ($issue in $issues)
   <tr>
      <td width="5%">&nbsp;</td>
      #issueLineItem ($issue)
      <td nowrap>
         #if($issue.getAssignee())
            $issue.getAssignee().getDisplayName()
         #else
            $i18n.getText('common.concepts.unassigned')
         #end</td>
       <td nowrap>$outlookDate.format($issue.getUpdated())</td>
   </tr>
#end

But for this to work you need to have got a collection of issues to do the foreach on from somewhere.

I don't see you doing that anywhere in the code you have posted.

Perhaps it will help if you study the code in the tutorial to see where it comes from in that example.

Prashant Mali May 18, 2017

#foreach ($mapEntry in $velocityParams.entrySet())
<tr>
<td>$mapEntry.key</td>
<td>$mapEntry.value</td>
</tr>
#end

This code is not working for me. something gonna wrong

Prashant Mali May 28, 2017

Still I am getting problem to show data on Velocity template using GetHtml method.

Kindly Please reply me on this

 

Sam Hall
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 28, 2017

Hi Prashant - can you give more information so that someone in the community may help you? We're users just like you, so it is difficult to help without more details.

When you say 'not working', what is not working? Code won't compile? Run-time error? Not displaying what you expect?

What error messages you are seeing? 

If no error message, please give some more details about what you are trying to display. What are you expecting to see? What do you actually see?

I would also recommend you try asking for help on the dedicated developer's community. It is much better suited to questions like this: https://developer.atlassian.com/community/

0 votes
Pooja Singh May 12, 2017

I have raised the same question here

0 votes
Pooja Singh May 12, 2017

I have raised the same question Here

Suggest an answer

Log in or Sign up to answer