0

I am creating a jira plugin, and I currently have a webwork module. I have the following class to represent the webwork:

public class ReportWebworkAction extends JiraWebActionSupport {

    private ArrayList<String> dataList = new ArrayList<String>();
    private String temp;

    //setters and getters for all varaibles

    @Override
    public String doDefault() throws Exception {
         //1) make http request
         //2) parse json data
         //3) display list of data in html table using velocity.vm

          return super.doDefault();
    }
}

Right now I am able to successfully make the http request and parse the data into a list of java objects. How can I look through that list in my velocity page and for each item create a element to display the data.

This is what I want to do:

#foreach($item in $dataList) {
    <tr>
          <td>$item.key</td>
          <td>$item.name</td>
          <td>$item.value</td>
    </tr>
}
#end

My velocity page can't seem to recognize the $dataList item which is an ArrayList variable in my ReportWebworkAction class. It can access the string variable temp however.

I read that I need to use the Content Provider and the getContextMap() method, but I am confused of how to use that in a separate class. Can someone show me the correct way to do this? Thanks.

juicymango
  • 201
  • 1
  • 4
  • 14

1 Answers1

0

You neeed getter: getDataList() in your WebWork class to be able to access it in velocity template. WebWork class members are transfered through accessors (getters).

And yes getContextMap() is also a solution but it's tedious to put your object manually into context. WebWork do it automatically with use of properly named accessors.

Bazyl
  • 68
  • 1
  • 5
  • @Bazl is webwork module the only module that can put the object in context. Are there other plugin modules that can do that? For what plugin modules would I have to use getContextMap()? – juicymango Dec 07 '16 at 15:05
  • hmm, i don't know any other modules that works like this. As far as i know when you implement your own custom field when you need to pass some objects to the templates you need to implement getVelocityParameters(Map context) and then you put objects to this parameter map. I am not aware of any other modules. – Bazyl Dec 07 '16 at 15:18