Update one f:dropdownList when a selection is changed in another

87 views
Skip to first unread message

Kirill

unread,
Oct 27, 2015, 11:34:13 AM10/27/15
to Jenkins Developers
Hi noble Jenkins developers!

It's quite easy to update one simple select (<f:select />) when another is changed (see DynamicDropDownListBox from Jenkins UI Samples plugin). But what about case when there are two <f:dropdownList/> elements?

I have used DropdownList from UI Samples as a sample to create these:

    <f:block>
        <table>
            <j:set var="currentArtifactDefinition" value="${instance.artifacts}"/>
            <f:dropdownList name="artifacts" title="Artifact">
                <j:forEach var="desc" items="${descriptor.artifactDescriptors}" varStatus="loop">
                    <j:set var="artifactDescription" value="${desc.class.name==currentArtifactDefinition.artifactsClassName?currentArtifactDefinition:null}"/>
                    <f:dropdownListBlock title="${desc.displayName}" value="${loop.index}" selected="${artifactDescription!=null}" staplerClass="${desc.entityClass.name}">
                        <st:include page="${desc.configPage}" from="${desc}"/>
                    </f:dropdownListBlock>
                </j:forEach>
            </f:dropdownList>
        </table>
    </f:block>

    <f:block>
        <table>
            <j:set var="currentScheduleDefinition" value="${instance.schedule}"/>
            <f:dropdownList name="schedule" title="Schedule">
                <j:forEach var="desc" items="${descriptor.scheduleDescriptors}" varStatus="loop">
                    <j:set var="scheduleDescription" value="${desc.class.name==currentScheduleDefinition.scheduleClassName?currentScheduleDefinition:null}"/>
                    <f:dropdownListBlock title="${desc.displayName}" value="${loop.index}" selected="${scheduleDescription!=null}" staplerClass="${desc.entityClass.name}">
                        <st:include page="${desc.configPage}" from="${desc}"/>
                    </f:dropdownListBlock>
                </j:forEach>
            </f:dropdownList>
        </table>
    </f:block>

There are two methods in Descriptor of the build step that has this config.jelly, they provide the data for both dropdowns:

    public DescriptorExtensionList<MyBuildStep.ScheduleDefinition, Descriptor<MyBuildStep.ScheduleDefinition>> getScheduleDescriptors() {
        return Jenkins.getInstance().getDescriptorList(MyBuildStep.ScheduleDefinition.class);
    }

    public DescriptorExtensionList<MyBuildStep.ArtifactDefinition, Descriptor<MyBuildStep.ArtifactDefinition>> getArtifactDescriptors() {
        return Jenkins.getInstance().getDescriptorList(MyBuildStep.ArtifactDefinition.class);
    }

But how can I handle the change event in the first one to customize the selection in the second one?

Stephen Connolly

unread,
Oct 27, 2015, 8:14:34 PM10/27/15
to jenkin...@googlegroups.com
It cannot, as you have rendered the whole page before the user can
select anything and the tag was not written to support list filtering.

The way to handle this would be to use a "wrapper" for the first drop
down and then render the second drop down within the wrapper always...
that means you will have NxM of the second drop down instances, but
only ever one active at any point in time...

But that would be an ugly hack...

Are you sure you cannot think of another way to achieve this?

(e.g. could you *enable and disable* some of the second descriptors
via Javascript from a doCheckArtifact method's response? It would seem
reasonable to show the full list and grey out the ones that are not
valid for the artifact selection)
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-dev/3744b377-beb9-4614-b6ec-8ac791b5e0a0%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Kirill

unread,
Nov 4, 2015, 3:56:55 PM11/4/15
to Jenkins Developers
Hi Stephen,

Thanks for suggestion "*enable and disable* some of the second descriptors via Javascript from a doCheckArtifact method's response?"! But can you please explain how to do some actions on the page on this method response? doCheckArtifact() will be run on server, how is it possible to customize its effect on the config page (e.g. - to disable an entry in another dropdown)?

Also, can you tell more about the wrappers you mentioned, perhaps share a link?

P.S. Another thing regarding dropdown selection change. http://javadoc.jenkins-ci.org/hudson/util/ListBoxModel.html says that one can use " "updateListBox" function, defined in hudson-behavior.js". This function doesn't seem to be there (https://github.com/jenkinsci/jenkins/blob/master/war/src/main/webapp/scripts/hudson-behavior.js?source=cc). Looks like the Javadoc is wrong?

Regards,
Kirill.

среда, 28 октября 2015 г., 2:14:34 UTC+2 пользователь Stephen Connolly написал:

Stephen Connolly

unread,
Nov 4, 2015, 4:10:43 PM11/4/15
to jenkin...@googlegroups.com
The doCheckArtifact() method returns a FormValidation which gets rendered as a HTML response that gets injected into the page in the validation area...


Kirill

unread,
Nov 10, 2015, 4:11:37 AM11/10/15
to Jenkins Developers
Do you mean something like

return FormValidation.respond(isFieldValid? FormValidation.Kind.ERROR : FormValidation.Kind.OK, "<script>disableBadStuff()</script>");

?

I tried this and it doesn't work :( The tag is injected in validation area, but the script inside it does not get executed :( And there are no errors reported.

Regards,
Kirill.


среда, 4 ноября 2015 г., 21:10:43 UTC пользователь Stephen Connolly написал:

Jesse Glick

unread,
Nov 10, 2015, 9:48:06 AM11/10/15
to Jenkins Dev
On Tue, Oct 27, 2015 at 11:34 AM, Kirill <yam...@gmail.com> wrote:
> what about case when there are two <f:dropdownList/> elements?

First of all, you should be using `f:dropdownDescriptorSelector` for
data binding, rather than a raw `f:dropdownList`.

Probably what you are asking for is not possible without either
patching Jenkins core, or producing your own form controls from
scratch. `f:select` computes its values dynamically, using an adjunct
(`select.js`). You would need a hybrid.

Just one of many inconsistencies and missing features in the stock
form controls, I am afraid.

Kirill

unread,
Nov 12, 2015, 9:21:25 AM11/12/15
to Jenkins Developers
Hi Jesse,

Thanks for suggestion about using dropdownDescriptorSelector! However, I was using an example from ui-samples-plugin, it's almost an exact replica. So I guess this sample plugin should be updated as well.

Do you have a more interactive community, like an IRC chat? I'd like to invest into enhancing UI controls and have a few suggestions regarding UI testing, Jelly controls and - what's most important - user documentation. What's the best way to discuss them and start implementing if considered needed?

Regards,
Kirill.


вторник, 10 ноября 2015 г., 14:48:06 UTC пользователь Jesse Glick написал:

Jesse Glick

unread,
Nov 12, 2015, 1:29:21 PM11/12/15
to Jenkins Dev
On Thu, Nov 12, 2015 at 9:21 AM, Kirill <yam...@gmail.com> wrote:
> I guess this sample plugin should be updated as well.

Pull requests welcome.

> Do you have a more interactive community, like an IRC chat?

https://wiki.jenkins-ci.org/display/JENKINS/IRC+Channel

> I'd like to
> invest into enhancing UI controls and have a few suggestions regarding UI
> testing, Jelly controls and - what's most important - user documentation.
> What's the best way to discuss them and start implementing if considered
> needed?

Some mixture of dev list messages, IRC, pull requests, and of course
research and experimentation.

Kirill Shepitko

unread,
Nov 13, 2015, 3:22:13 AM11/13/15
to jenkin...@googlegroups.com
Thanks a million, I'll start working on this.


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/gsxlpIJLQ_U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr27U-wnbFZb_ZgWm2yyWifOe_xPb510S42mBKAXFrg4Xg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages