I've looked around and seen a couple of other topics related to this, but none of the solutions presented seemed to fix my issue. I used the command line to generate a basic plugin that adds a new project panel, and I'm attempting to call a method from the generated Java file.
My atlassian-plugin.xml includes this:
<component key="myPluginComponent" class="com.atlassian.jira.MyPluginComponentImpl" public="true"> <interface>com.atlassian.jira.MyPluginComponent</interface> </component>
And my sample method is stubbed in MyPluginComponent
String show();
And is implemented in MyPluginComponentImpl as:
public String show() { return "Test String"; }
I've tried calling it from Velocity using $show, $show(), $action.show, $action.show(), $myPluginComponent.show, and $myPluginComponent.show()
I have also tried overriding the getVelocityParameters function to add ("instance", this) and calling $instance.show and $instance.show(). So far everything I has tried has just returned my method call as a literal
For example, this just gets me:
Testing...
$show
<div class="mod-header"> #set($message = "Testing...") $message $show </div>
Community moderators have prevented the ability to post new answers.
A velocity template can call methods from its webwork action. So add getter in your webwork action that returns MyPluginComponent and then you can call any MyPluginComponent method from the template:
// webwork action class public getMyPluginComponent() { return myPluginComponent; // myPluginComponent instance should be injected to the webwork action as constructor parameter } // template <div class="mod-header"> #set($message = $action.getMyPluginComponent().show()) $message </div>
Hmm. This is the first I've heard of webwork actions in all this. I'm checking out a couple of guides there now... I'm not sure I understand the purpose of the class outlined under component in the atlassian-plugin.xml file if you have to set up a webwork action for any Java function calls on the velocity page. What is it used for?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What type of the plugin are you developing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The eventual goal is a Project Panel Plugin. I'm hoping to extend this to display some gadgets I developed down the line, but for now I'm just trying to understand how to make Java calls from the Velocity template that's displayed in my panel.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My answer was for the webwork plugin. Sorry for the confuse. For the Project Panel Plugin you are expected to override getHtml from ProjectTabPanel interface. In case you extend from GenericProjectTabPanel, it already overrides getHtml and parses velocity template like this: public String getHtml(BrowseContext ctx) { final Map<String, Object> startingParams = JiraVelocityUtils.getDefaultVelocityParams(authenticationContext); startingParams.put("i18n", authenticationContext.getI18nHelper()); startingParams.put("project", ctx.getProject()); startingParams.put("fieldVisibility", fieldVisibilityManager); return descriptor.getHtml("view", startingParams); } You can override getHtml to pass one parameter: startingParams.put("show", myPluginComponent().show());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.