playing with database through projectTabPanel plugin

alexis June 2, 2015

Hi everyone,


I'm actually developping an extension for Jira.

I created a projectTabPanel plugin because I needed to call my plugin from this emplacement. My plugin also created a new table in activeObjects and I want to interact with it.

No problem with that, I did some tests and it worked perfectly well.

 

My problem is that my projectTabPanel call my velocity template and this template have a form with data that I want to save in my new table.
Here's my question : how to send those data from this page ? Which java class will that call ?

Thanks a lot for your help and sorry for my english^^

3 answers

1 accepted

0 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 2, 2015

Create a webwork action class and invoke it from the form. You can then persist the data in the action class.

See https://developer.atlassian.com/jiradev/jira-architecture/jira-technical-overview/jira-webwork-actions

0 votes
alexis June 4, 2015

Once again you gave me the solution, a great thanks for that !

Nevertheless, I've got some others problem, here's the situation :


From the view of my projectTabPanelPlugin I submit a form to a class of a WebWork plugin.
I can do most of the stuff I wanted to do inside the class but here's not actually the problem.

When this class return the "success" statement I want to go back to the view of my projectTabPanel and it works, the problem is that my left side column menu disapeared, how to get it back ?

My other worry is this : in my view I got a textarea and I want to fill it with the result of some treatment I did in the class of my WebWork plugin. I know how to display variables in the view but I have no idea how to send those variables from my WebWork class :/

Thanks for your help =)

EDIT : I just found how to display parameters in my view, thanks to ${action.myMethod()} !

0 votes
alexis June 3, 2015

Hi Jobin,

Thanks for your answer.

Following your advices I read the documentation and created a WebWork plugin which I linked to a template and a Javascript function. JIRA compile well, unfortunatly the WebWork plugin doesn't work.

Here's my code :


release-plugin.vm

<script type="text/javascript">
     #include("js/jira-version-plugin.js")
</script>
<h1> Release notes of version : </h1>
<select name="select">
  <option value=""></option> 
    #foreach($version in $versions)
        #if ( $version == $selected )
            <option value="$version" selected>$version</option> 
        #else
            <option value="$version">$version</option> 
        #end
    #end
</select>
<br/>
<textarea rows="40" cols="100">$description2 , $QueryString, $contextKey, $url, $contextKey</textarea> 
 <button onclick="test()">ok </button>

 

atlassian-plugin.xml

<?xml version="1.0" encoding="UTF-8"?>

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
  <plugin-info>
    <description>${project.description}</description>
    <version>${project.version}</version>
    <vendor name="${project.organization.name}" url="${project.organization.url}"/>
    <param name="plugin-icon">images/pluginIcon.png</param>
    <param name="plugin-logo">images/pluginLogo.png</param>
  </plugin-info>
  <!-- add our i18n resource -->
  <resource type="i18n" name="i18n" location="jira-version-plugin"/>
  <!-- add our web resources -->
  <web-resource key="jira-version-plugin-resources" name="jira-version-plugin Web Resources">
    <dependency>com.atlassian.auiplugin:ajs</dependency>
    <resource type="download" name="jira-version-plugin.css" location="/css/jira-version-plugin.css"/>
    <resource type="download" name="jira-version-plugin.js" location="/js/jira-version-plugin.js"/>
    <resource type="download" name="images/" location="/images"/>
    <context>jira-version-plugin</context>
  </web-resource>
  <!-- publish our component -->
  <component key="myPluginComponent" class="com.test.MyPluginComponentImpl" public="true">
    <interface>com.test.MyPluginComponent</interface>
  </component>
  <!-- import from the product container -->
  <component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties"/>
  <project-tabpanel key="release-plugin" name="Release Plugin" i18n-name-key="release-plugin.name" class="com.test.jira.tabpanels.ReleasePlugin">
    <description key="release-plugin.description">The Release Plugin Plugin</description>
    <label key="release-plugin.label"/>
    <order>10</order>
    <resource type="velocity" name="view" location="templates/tabpanels/release-plugin.vm"/>
    <web-resource key="ajax-actions">
      <resource type="download" name="jira-version-plugin.js" location="js/jira-version-plugin.js"/>
      <context>com.test.jira.tabpanels</context>
    </web-resource>
  </project-tabpanel>
  <ao key="ao-module">
    <description>The module configuring the Active Objects service used by this plugin</description>
    <entity>com.test.jira.ao.releaseplugin.ReleaseNotes</entity>
  </ao>
  <component-import key="ao" name="Active Objects service" interface="com.atlassian.activeobjects.external.ActiveObjects">
    <description>Component to access Active Objects functionality from the plugin</description>
  </component-import>
  
  
  
  
  <webwork1 key="SaveEntity" name="SaveEntity" i18n-name-key="SaveEntity.name">
    <description key="SaveEntity.description">The SaveEntity Plugin</description>
    <actions>
      <action name="com.test.jira.tabpanels.SaveEntity" alias="SaveEntity">
        <view name="success">templates/tabpanels/release-plugin.vm</view>
        
           <command name="test" alias="SaveEntityOne">
            <view name="success">templates/tabpanels/release-plugin.vm</view>
        </command>
        
      </action>
    </actions>
  </webwork1>

  
</atlassian-plugin>

 

SaveEntity.java

package main.java.com.test.jira.tabpanels;

import java.util.*;

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.ofbiz.OfBizDelegator;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.browse.BrowseContext;
import com.atlassian.jira.project.version.Version;
import com.atlassian.jira.web.action.JiraWebActionSupport;
import com.atlassian.query.Query;

public class SaveEntity extends JiraWebActionSupport {

    protected String doExecute() throws Exception {
        System.out.println("TEST SUCCEED");
        return SUCCESS;
    }

    protected String doTest() throws Exception {
        System.out.println("TEST SUCCEED2");
        return SUCCESS;

    }

}

 

jira-version-plugin.js

function test() {
    alert("!!!!!!!hello world!!!!!!!!");
    window.location = "/SaveEntity!test"
}

 

When I load my template page doExecute isn't called. When I click on the javascript button I got the alert "hello world" but it does redirect me on a white page and not the same template as expected...
I have no idea why and no errors in the logs :/
Thanks again for your help !

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 3, 2015

This is not how you do things in webwork. But it is a lot to teach in a forum ;) For starters, you are redirecting to "/SaveEntity!test" which is wrong. It should be "JIRA_BASE_URL/secure/SaveEntity!test.jspa". You should also do it in a form action instead of redirecting from java script.

Suggest an answer

Log in or Sign up to answer