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

How do I render a velocity template inside a issue tab panel?

Dyllen Owens May 24, 2015

I followed this extremely simple tutorial https://bitbucket.org/bhushan154/jira-issue-tab-panel-tutorial/wiki/Home to add a new issue tab panel. It shows how you can add simple content to the page using stringBuilder. Ideally I would want to use a velocity template as it's much easier to work with and separates the logic appropriately. I have a template file, that contains:

<div class="mod-header">
    <h3>$i18n.getText('service-now-tab-panel.label')</h3>
</div>

I've tried fiddeling around with this attempting to get it to display data appropriately, it's not doing anything and isn't rendering out content onto the issue detail page. Here's the controllers it's barebones right now as I need to get passed this road block.

package com.verys.jira.plugins.panels;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.jira.plugin.issuetabpanel.AbstractIssueTabPanel;
import com.atlassian.jira.plugin.issuetabpanel.IssueTabPanel;
import com.atlassian.jira.issue.tabpanels.GenericMessageAction;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.crowd.embedded.api.User;
import java.util.Collections;
import java.util.List;

public class ServiceNowTabPanel extends AbstractIssueTabPanel implements IssueTabPanel
{
    private static final Logger log = LoggerFactory.getLogger(ServiceNowTabPanel.class);

    public List getActions(Issue issue, User remoteUser)
    {
        return Collections.singletonList(new GenericMessageAction("" + issue.getReporter().getDisplayName() + ""));
    }


    public boolean showPanel(Issue issue, User remoteUser)
    {

        return true;
    }
}

The documentation for rendering out velocity templates on issue tab panels is extremely sparse and almost non existent. If someone can just kindly point me in the right direction that would be great.

Also here is the properties file

<issue-tabpanel key="service-now-tab-panel" name="Service Now Tab Panel" i18n-name-key="service-now-tab-panel.name" class="com.verys.jira.plugins.panels.ServiceNowTabPanel">
  <description key="service-now-tab-panel.description">The Service Now Tab Panel Plugin</description>
  <label key="service-now-tab-panel.label">Plugin Test</label>
  <order>10</order>
  <resource type="velocity" name="view" location="templates/tabpanels/service-now-tab-panel.vm"/>
  <supports-ajax-load>true</supports-ajax-load>
</issue-tabpanel>

As you can see it has the resource view that points to the correct destination of the .vm file.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Volodymyr Krupach
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 24, 2015

Hi Dyllen!

getActions should return  List<IssueAction> and HTML generation is supposed to happen in your IssueAction implementation, getHtml method. You can extend your IssueAction implementation from AbstractIssueAction and it already overrides getHtml() by rendering velocity template named "view".

For more info about Issue Tab panel, please see here https://answers.atlassian.com/questions/15835336

S M March 23, 2017

I as well am struggling through using velocity has it pertains to the issue panel so I appreciate the comments. I am curious if the post you provided your passing parameters to velocity direct and not using the getHtml() method. How then does the getHtml() method relate to the populateVelocityParams? Thank you

Volodymyr Krupach
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.
March 23, 2017

Hi Steven M,
AbstractIssueAction provides implementation for getHtml:

public String getHtml() {
        Map params = new HashMap();
        populateVelocityParams(params);
        return descriptor.getHtml("view", params);
    }

    protected abstract void populateVelocityParams(Map params);

And remember sources are your best friend in Atlassian development world smile

S M March 28, 2017

Thank you! Defiantly directed me down the correct rabbit trail. If I'm following the API correctly it's the IssueTabPanelModuleDescriptor field on AbstractIssueAction which provides the appropriate

String getHtml(String resourceName, Map&lt;String,?&gt; startingParams)

method.

I'm passing in a

HashMap&lt;String, ArrayList&lt;String&gt;&gt; results

which is a database query through to the populateVelocityParams.

public String getHtml() {
        bambooQueryResults();
        populateVelocityParams(results);
        return descriptor.getHtml("buildInfo", results);
    }

	protected void populateVelocityParams(Map results) {
	}

and in Velocity

#foreach ($build in $results.keySet())
    $results.size()
    $build.key
#end

Still working on why this is not rendering anything.

S M March 28, 2017

I'm also taking you up on your suggestion of getting the source code. I have a case open with Atlassian as it indicates for our license we do not have access to those files. I'm unsure what service level we need to have in order to acquire the source code but looking into it. Thank you.

TAGS
AUG Leaders

Atlassian Community Events