codeCompiler77
codeCompiler77

Reputation: 516

Jelly Config Expand Elements

I have a quick question. In jenkins when making the jelly config file for the gui, you can have a radio button expand and show more elements, can this be done with a drop down list as well? If so, does anyone have an example please? I know how to do it with radio buttons but i don't want radio buttons, I need the content to be dependant on the choice.

Edit: Currently I have the following:

   <f:entry title="${%Authentication}" field="authMode">
        <f:select />
    </f:entry>

and in the java file:

    public ListBoxModel doFillAuthModeItems() {
        ListBoxModel items = new ListBoxModel();
        items.add("None");
        items.add("Form Based Authentication");
        items.add("Script Based Authentication");
        return items;
        }

This creates a drop down list of 3 elements, i just need to show different content based on the selection, for example. None would have no new content, Form Based would show a username and a password textfield.

Upvotes: 0

Views: 298

Answers (1)

KeepCalmAndCarryOn
KeepCalmAndCarryOn

Reputation: 9075

What you need to research is the hetero-list jelly tag. There is a good page on it from cloud bees their code is closed though

I put an open source one together for the selenium-axis-plugin but this is in groovy and using groovy forms

namespace(lib.FormTagLib).with {
    entry(title: _("Name"), field:"name") {
        textbox( default:"label")
    }
    block{
        entry(field:"seleniumCapabilities") {
            hetero_list( name: "seleniumCapabilities",
                      hasHeader: true,
                      descriptors:descriptor.axisItemTypes(),
                      items:      instance? 
                           instance.getSeleniumCapabilities():
                           descriptor.loadDefaultItems())
        }
    }
}

source

How it works is that there a method on the top level descriptor which returns all the descriptors which can be used

List<ItemDescriptor> axisItemTypes() {
    def ait = Jenkins.instance.<Item,ItemDescriptor>getDescriptorList(Item)

    def ret = []

    for (int i = 0; i < ait.size(); i++) {
        /*code removed*/
        ret.add(ait.get(i))
    }
    ret
}

source

All of the nested items have to have their own descriptors and also a @DataBoundConstructor

Upvotes: 1

Related Questions