Pergunta

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

Foi útil?

Solução

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:

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top