How to add webwork action to a project panel?

自作多情 提交于 2019-12-24 04:41:09

问题


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. 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).

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

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


回答1:


To your first question:

have a look at: Project Tab Panel Module

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.

So what you would have to do:

  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();

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

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

  5. 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>

  6. 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

To your second question:

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.



来源:https://stackoverflow.com/questions/18594894/how-to-add-webwork-action-to-a-project-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!