如何将Web动作添加到项目面板? [英] How to add webwork action to a project panel?

查看:115
本文介绍了如何将Web动作添加到项目面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用网络操作和项目选项卡模块制作了自己的插件(单独).但是现在我需要将两者结合起来:将有一些组合框和一个按钮可以使插件计算统计信息.我需要在同一项目标签中显示它.

I have made my own plugins (separate) with webwork actions and with project tab modules. But now I need to combine both: there will be some comboboxes and a button that make the plugin calculate statistics. I need to show it in the same project tab.

我在这两个步骤上都遇到了麻烦:

I am having trouble with both steps:

  1. 将显示如何在项目选项卡之前执行任何Java代码,并生成此页面的内容以及Java代码将从userManager,groupManager等检索的信息(用用户名填充组合框).

  1. How to do any Java code BEFORE project tab will be shown, and generate contents of this page with info that Java code will retrieve from userManager, groupManager etc. (fill combobox with usernames).

在用户按下计算!"后如何在同一页面上输出新信息.按钮(针对所选用户的统计信息).

How to output new info on the same page after user presses the "Calculate!" button (calculated stats for selected user).

我认为我需要在项目面板标签上重新定义一些方法(例如"renderPage").

I think I need to redefine some methods on my project panel tab (something like "renderPage").

推荐答案

第一个问题:

看看:项目标签面板模块

您必须在其中设置的类负责呈现项目"选项卡面板.在正常情况下,您可以在那里渲染一些速度模板.请查看VersionsProjectTabPanel实现的接口之一(

the class you have to set there is responsible for rendering the project tab panel. in normal cases you render some velocity templates there. have look at one of the interfaces VersionsProjectTabPanel implements (com.atlassian.jira.plugin.browsepanel.TabPanel). there you will find a method named getHtml(...). Jira will call this Method before the Panel is displayed in the web page.

那么您将要做的事情:

  1. 定义一个实现 TabPanel 界面,并在atlassian-plugin.xml
  2. 中的项目"选项卡面板模块描述符中设置此类.
  3. 覆盖方法
  1. define a class that implements the TabPanel interface AND set this class in the project tab panel module descriptor in your atlassian-plugin.xml
  2. overwrite the method getHtml(...) with your own template rendering process
  3. in your overwritten method you have to get a reference to the VelocityManager:

VelocityManager velocityManager = ComponentManager.getInstance().getVelocityManager();

编写速度模板,并使用

Write velocity template and render it with getBody(...) Method:

String renderedText = velocityManager.getBody("<PATH_TO_TEMPLATE>", "templatename.vm", context);

如果要将内容传递给该模板,请通过

If you want to pass content to that template, do that via the context variable of the getBody(...) Method. The Map is of type Map<Object, Object>. Usually you will put in there a String/Object Entry. The Key-String will be declared as variable in the template and the Value-Object is the value of the variable: Map<String, Object>

renderedText 作为返回值提供给

give that renderedText as return-Value to the caller of getHtml(...) and it will be displayed on the page.

有关该主题的一些问答和教程页面:

Some Q&A and tutorial pages to that topic:

  • Use Velocity Template in Jira Plugin
  • Velocity Templates

只需在力度模板中声明一个<form>...</form>标签即可.其中的操作属性应指向您的网络操作操作网址.在 getHtml(...)已被覆盖的方法,您必须访问

Just declare a <form>...</form> tag in your velocity template. The action-attribute in there should point to your webwork action url. In the getHtml(...) Method you have overwritten, you have to access the HttpServletRequest context via ServletActionContext:

HttpServletRequest request = ServletActionContext.getRequest();
String someRequestParam = request.getParameter("paramName");

通过我们之前讲过的模板上下文映射将请求参数内容传递给您的速度模板,或使用它进行一些业务逻辑.

Pass the request param content to your velocity template via template context map we spoke before or do some business logic with it.

这篇关于如何将Web动作添加到项目面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆