Jenkins插件下拉菜单 [英] Jenkins plugin drop-down menu

查看:656
本文介绍了Jenkins插件下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以某种方式,我无法从下拉菜单中存储值,而下拉菜单是我为Jenkins插件添加到jelly.xml中的.另一方面,文本字段也可以正常工作

Somehow I am not able to store values from drop-down menus, that I added to the jelly.xml for my Jenkins plugin. Text fields work just fine on the other hand

果冻:

<f:entry title="Catch+ Version" field="selection">
  <f:select/>
</f:entry>

我没有向数据绑定构造函数添加任何内容.也许这已经是问题了.我不知道如何添加它,因为它不是字符串而是列表?!

I added nothing to the databound constructor. Maybe this is already the problem. I didn't know how to add it, since it's not a string but a list?!

所以我只添加了doFillSelectionItems函数,该函数应该可以正常工作.

So I only added the doFillSelectionItems function, which works as it should.

public ListBoxModel doFillSelectionItems()
{
    return new ListBoxModel(new Option("1.13", "1.13"),
                    new Option("1.14", "1.14"),
                    new Option("1.15", "1.15"));
}

以及save()之前的configure方法:

and also to the configure method before save():

catchVersion = formData.getString("selection");

毫无疑问,我可以在三个选项之间切换,并存储值.我可以运行几次构建,​​并使用选择的值BUT:如果我再次配置项目,则无论我之前选择了什么,总是会选择第一个选项.如何使储值出现在这里?

I can change between the three Options and the value is stored, no doubt. I can run the build several times and it's using the selected value, BUT: if I go to configure project again, always the first option is selected, no matter what I had chosen before. How can I make the stored value appear here?

推荐答案

Option构造函数的第三个参数定义了当前选择.您也可以在中传递当前值

There is a third parameter to the Option constructor which defines the current selection. You can also pass the current value in

public ListBoxModel doFillSelectionItems(@QueryParameter String selection) {
    return new ListBoxModel(new Option("1.13", "1.13", selection.matches("1.13") ),
                    new Option("1.14", "1.14", selection.matches("1.14") ),
                    new Option("1.15", "1.15", selection.matches("1.15") ));
}

改编自此处,但这是使用全局配置的示例

Adapted from here but this is an example using the global config

这篇关于Jenkins插件下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆