在 Jira 4.4 中将参数放入速度上下文中

发布于 2024-12-23 00:19:27 字数 1348 浏览 3 评论 0原文

我正在开发一个插件来显示与项目相关的附加信息。

因此,我正在开发一个项目选项卡面板模块,但我的页面不显示我放入速度上下文中的参数。

这是插件 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"/>

这里是我的类的有用部分:

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;
}

}

因此,就像在本例中一样,当我在模板中写入 `$testvalue 时,数字不会显示。

我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御守 2024-12-30 00:19:27

问题在于,用于返回选项卡 HTML 的 getHtml 方法有一个作为 Velocity 上下文的 Map,但仅包含 BrowseContext 对象中的参数。解决此问题的方法是重写类中的 createVelocityParams,例如

protected Map createVelocityParams(final BrowseContext ctx) {
地图参数 = super.createVelocityParams(ctx);
params.put("myparam", "它的一些值");
返回参数;
问题

是该方法是受保护的,所以我最终还重写了 getHtml,它在父类中调用 createVelocityParams 。

某些项目选项卡扩展了 GenericProjectTabPanel,但某些项目选项卡(例如 SummaryProjectTabPanel.java)似乎使用 UI 片段。我怀疑碎片是事情正在发展的方向。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文