使用Jira在velocity模板中调用Java方法时出现问题

使用Jira在velocity模板中调用Java方法时出现问题,java,plugins,call,jira,velocity,Java,Plugins,Call,Jira,Velocity,我正在为jira开发一个插件,其中包含一个自定义字段类型。 该字段是选择字段,必须用选项填充。我通过Jira方法getVelocityParameters()提供这些选项 @覆盖 公共地图getVelocityParameters(发布, CustomField字段、FieldLayoutItem字段LayoutItem){ Map Map=super.getVelocityParameters(问题、字段、字段布局项); put(“customOptions”,getCustomOptions

我正在为jira开发一个插件,其中包含一个自定义字段类型。 该字段是选择字段,必须用选项填充。我通过Jira方法getVelocityParameters()提供这些选项

@覆盖
公共地图getVelocityParameters(发布,
CustomField字段、FieldLayoutItem字段LayoutItem){
Map Map=super.getVelocityParameters(问题、字段、字段布局项);
put(“customOptions”,getCustomOptions());
返回图;
}
getCustomOptions()返回包含所需选项的哈希表

为了访问和显示这些选项,我在模板中使用了#foreach循环:

    #foreach($customOption in $customOptions)
        <option id="$customOption.Id" value="$customOption.Value">
               $customOption.Label
        </option>
    #end
#foreach($customOption中的$customOptions)
$customOption.Label
#结束
它不显示返回的对象,只显示文本本身,只正确显示“$customOption.Id”。 仅写入“$customOption”将显示对对象的整个引用。 因此,我可以访问对象及其id,但不能访问其他属性

Id是一个int,而label和value是字符串

我寻找解决方案并尝试了不同的方法来解决这个问题,例如: $!customOption.Label,${!customOption.Label},${customOption.Label},$customOption.getLabel()

我在这里找不到问题,因为id工作正常


因为你使用的是地图,所以用Sry来表示残破的英语。

。因此,请尝试以下方法:

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

如果您的问题没有价值,Velocity将显示来源


例如,如果您想获得customfield值,您应该检查该值,如果未设置该值,您可以加载默认值或忽略它。

我认为您应该了解这样一个事实,即Velocity类只有在该字段具有公共get方法时才会显示字段值

假设customOption是类X的对象,那么类X必须有一个返回标签的公共get()方法

标签字段是否是类X的公共字段并不重要,公共get()方法是必需的


谢谢您的帮助,但问题似乎是某些值包含NULL。谢谢你的打扰。您的解决方案帮助我找到了问题。@Joromo如果您尝试检查
NULL
,我刚刚更新:-)方法返回NULL,因此没有正确显示任何内容。我假设出现异常或“”而不是仅显示“$customOption.Label”。不管怎么说,这是一件令人讨厌的事。
#foreach($customOption in $customOptions)
  #if ($customOption)
    #foreach ($co in $customOption.keySet())                       
         $customOption[$co]           
    #end
  #end
#end