GLF
GLF

Reputation: 75

Putting parameters in velocity context in Jira 4.4

I'm developing a plugin to display additional information related to a project.

So I'm developing a Project Tab Panel module but my page does not display the paramenters I put in the velocity context.

Here is the a part of plugin xml:

<project-tabpanel key="stats-tab-panel" name="Stats Tab Panel" i18n-name-key="stats-tab-panel.name" class="it.pride.jira.plugins.StatsTabPanel">
<description key="stats-tab-panel.description">The Stats Tab Panel Plugin</description>
<label key="stats-tab-panel.label"></label>
<order>10</order>
<resource type="velocity" name="view" location="templates/tabpanels/stats-tab-panel.vm"/>

Here instead the useful part of my class:

public class StatsTabPanel   extends GenericProjectTabPanel {

public StatsTabPanel(JiraAuthenticationContext jiraAuthenticationContext,
        FieldVisibilityManager fieldVisibilityManager) {
    super(jiraAuthenticationContext, fieldVisibilityManager);
    // TODO Auto-generated constructor stub

}


public String testvalue="112002";

@Override
public boolean showPanel(BrowseContext context){
    return true;
}

@Override
public Map<String, Object> createVelocityParams (BrowseContext context) {
    Map<String, Object> contextMap = createVelocityParams(context);
    contextMap.put("testvalue", testvalue);
    return contextMap;
}

}

So, as in this case, when i write `$testvalue in my template the number doesn't show up.

What am I doing wrong?

Upvotes: 2

Views: 1121

Answers (1)

mdoar
mdoar

Reputation: 6881

The problem is that the getHtml method that is used to return the HTML for the tab has a Map that is the Velocity context but only contains the params in the BrowseContext object. The way to fix this is to override createVelocityParams in your class, e.g.

protected Map createVelocityParams(final BrowseContext ctx) { Map params = super.createVelocityParams(ctx); params.put("myparam", "some value for it"); return params; }

The problem is that method is protected so I ended up also overriding getHtml which calls createVelocityParams in a parent class.

Some Project tabs extend GenericProjectTabPanel but some such as SummaryProjectTabPanel.java seem to use UI Fragments. I suspect that Fragments is what things are moving towards.

Upvotes: 1

Related Questions