【问题标题】:Jenkins Jelly Updating TextboxJenkins Jelly 更新文本框
【发布时间】:2014-10-03 14:31:57
【问题描述】:

是否可以在 Jelly 中动态更新文本框的值?

我有一个下拉框,其选项是根据表单中的先前数据确定的。使用在线提供的文档很简单(只需使用描述符中的doFill...Items() 方法)。每个选项代表一个"Property"。在下拉列表下,我有一个文本框,它代表属性的"Property Value"

果冻文件:

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
    <f:entry title="Property" field="property">
        <f:select />
    </f:entry>
    <f:entry title="Value" field="propertyValue">
        <f:textbox value="${descriptor.getDefaultValue()}" />
    </f:entry>
    <div align="right">
        <f:repeatableDeleteButton/>
    </div>
</j:jelly>

每次选择下拉框中的新项目时,我都想用属性的当前值更新文本框。我一直在尝试一些不同的事情,例如在 Jelly 文件中设置 defaultvalue 属性。但是,我还没有找到一种在表单初始化后触发文本框更新的方法。

描述符:

@Extension
public static class DescriptorImpl extends Descriptor<ProvisionPropertyParam> {
    /**
     * Gets a list of update properties for a specific component.
     *
     * @param component
     * @return ListBoxModel - the list of update properties for the component
     */
    public ListBoxModel doFillPropertyItems(@QueryParameter("component") @RelativePath("..") String component) {
        return ServiceManager.userInterfaceService().getProvisionProperties(component);
    }
    public String doFillPropertyValue(@QueryParameter("property") String property) {
        return ServiceManager.userInterfaceService().getPropertyValue(property);
    }
    public String getDefaultValue() {
        return "Test";
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public String getDisplayName() {
        return "Provision property";
    }
}

我可以使用getDefaultValue() 方法成功设置文本框的值。但是,我需要能够使用doFillPropertyValue(),或者一些以相同方式运行的不同名称的方法。我想它应该像在果冻文件中设置方法一样简单,但是有问题的方法有一个参数,考虑到我没有要发送的值,我不确定如何在果冻中调用方法它。

我试过设置:

<f:textbox value="${descriptor.doFillPropertyValue()}"/>

但它显然没有做任何事情。谁能给我一些指导?

【问题讨论】:

  • 你试过不加括号吗?

标签: java jenkins textbox jelly


【解决方案1】:

在我的果冻代码中,我使用了这样的东西:

    <j:forEach var="currentDescriptor" items="${descriptor.tilogiPlateformeDescriptors}" varStatus="loop">

在我的java代码中,方法是:

    public DescriptorExtensionList<TilogiPlateforme, TilogiPlateformeDescriptor> getTilogiPlateformeDescriptors()

【讨论】:

    【解决方案2】:

    doFill{Variable}Items 方法在您刷新页面或使用配置选项进入页面时调用。所以它的静态方法为页面调用了一次。

    Jelly Pages 支持 HTML 和 Javascript。对于下拉框,您可以使用onfocusonclick 方法作为onfocus = "populateTextbox()"

    使用简单的java脚本作为

    select = document.getElementById("Id of DropDown");
    selectedData = select.options.selected.text
    

    使用selectedData 值更新文本框

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多