0
votes

I´m developing a plugin for jira which contains a custom field type. The field is a select and has to be filled with options. I supply these options via the Jira method getVelocityParameters().

@Override
public Map<String, Object> getVelocityParameters(Issue issue,
        CustomField field, FieldLayoutItem fieldLayoutItem) {

     Map<String, Object> map = super.getVelocityParameters(issue, field, fieldLayoutItem);
     map.put("customOptions", getCustomOptions());

     return map;
}

getCustomOptions() returns a Hashtable with the Options i need.

To access and display these options i used a #foreach loop in the template:

    #foreach($customOption in $customOptions)
        <option id="$customOption.Id" value="$customOption.Value">
               $customOption.Label
        </option>
    #end

Instead of showing the returned Objects it simply just display the text itself, only the "$customOption.Id" is displayed correctly. And writing only "$customOption" shows the whole reference to the object. So i CAN access the object and its id but not the other properties.

Id is an int, while label and value are Strings.

i searched for solutions and tried different things to solve this problem, e.g.: $!customOption.Label, ${!customOption.Label}, ${customOption.Label}, $customOption.getLabel()

I can´t find the problem here, because the id is working properly.

Sry for the broken english.

3
The methods returned NULL therefore nothing was displayed properly. I assumed an Exception or a "" instead of just displaying "$customOption.Label". Anyways ty. - Don

3 Answers

0
votes

Because you use Map. So try the following:

#foreach($customOption in $customOptions)
  #if ($customOption)
    #foreach ($co in $customOption.keySet())                       
         $customOption[$co]           
    #end
  #end
#end
0
votes

Velocity will display the source if there is no value for your issue.

E.g. if you want to obtain a customfield value, you should check the value and if its not set you can either load the default value or just ignore it.

0
votes

I think you should look into the fact that Velocity will only display a field value if its class has a public get method for that field.

Say customOption is an object of class X, then class X must have a public get() method that returns the label.

It does not matter if the label field is a public field of class X, public get() method is necessary.

You can have a look at this for reference: