Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Velocity Template for Webwork Action is missing Context

Christian Werner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 2, 2022

Hi all,

I am currently trying to create a Jira Plugin and am struggling with context provision for a velocity template that is being used in a webwork module. 

I created a Web-Panel first, where it was possible to reference a ContextProvider class and everything worked fine.

Now, I want to build pretty much the same page, but instead of using a Web-Panel I want to use a Webwork module. The problem for me here is, that my velocity template is somehow missing context and in comparison to the Web-Panel I am not providing one (no context-provider). How can I make the context known to the velocity template?

I am kind of new in software development and thus the solution may be very simple, but for me unfortunately it is not. I would be very greatful, if anyone could explain to me (in a simple and understandable way) how I can solve my problem. Thanks in advane!

Here are the important code snippets.

Webwork:

<webwork1 key="project-panel-module" name="Project Panel Module" i18n-name-key="project-panel-module.name"> 
<description key="project-panel-module.description">The Project Panel Module Plugin</description>
<actions>
<action name="com.atlassian.jira.testtron.webwork.ProjectPanelAction" alias="ProjectPanelAction">
<view name="project-panel">/templates/project/project-panel.vm</view>
</action>
</actions>
</webwork1>

ProjectPanelAction class:

@SupportedMethods({RequestMethod.GET})
public class ProjectPanelAction extends JiraWebActionSupport
{
private static final Logger log = LoggerFactory.getLogger(ProjectPanelAction.class);

@Override
public String execute() throws Exception {

return "project-panel";
}

}

Context Provider class that worked for the Web-Panel:

@Named
public class JobPanelContextProvider implements ContextProvider {

private final JobServiceAdapter jobServiceAdapter;

@Inject
public JobPanelContextProvider(JobServiceAdapter jobServiceAdapter) {
this.jobServiceAdapter = jobServiceAdapter;
}

@Override
public Map<String, Object> getContextMap(Map<String, Object> context) {
final ResultDisplay jobDisplays = jobServiceAdapter.readFeatureJobListForHead();
context.put("resultDisplay", jobDisplays);

return context;
}
}

 

Part of the Velocity Template. Basically none of the variables can be resolved:

<table id="delayedSortedTable" class="aui aui-table-sortable">
<thead>
<tr>
<th>Issue</th>
<th>Erfolgreich</th>
<th>Fehlgeschlagen</th>
<th>Total</th>
<th class="aui-table-column-unsortable"></th>
</tr>
</thead>
<tbody>
#foreach( $job in $resultDisplay.jobs )
<tr>
<td><a href="$job.issueLink">$job.issueDisplayName</a></td>
<td>
<aui-badge>$job.successful</aui-badge>
</td>

 

0 answers

Suggest an answer

Log in or Sign up to answer