@QueryParameter in form validation is not filled for dropdownDescriptorSelector

22 views
Skip to first unread message

Ullrich Hafner

unread,
Mar 21, 2018, 3:53:36 PM3/21/18
to Jenkins Developers
I’m trying to use form validation on a dropdownDescriptorSelector, however here the validation method parameters (annotated with @QueryParameter) are not found and set to null (or 0). (If used standalone the validation works).

Is there anything different with a dropdownDescriptorSelector?

The relevant main jelly part:

<f:entry description="${description.tool}">
<f:dropdownDescriptorSelector field="tool" title="${%title.tool}"
descriptors="${descriptor.availableTools}"/>
</f:entry>

The relevant jelly part of the referenced Describable:

<f:entry title="${%High priority threshold}"
description="${%Minimum number of duplicated lines for high priority warnings.}"
field="highThreshold">
<f:textbox default="50"/>
</f:entry>

My validation method:

public FormValidation doCheckHighThreshold(@QueryParameter final int highThreshold,
@QueryParameter final int normalThreshold) {
return VALIDATION.validateHigh(highThreshold, normalThreshold);
}

Both parameters are always set to zero when setting a breakpoint here.
signature.asc

Jesse Glick

unread,
Mar 21, 2018, 6:27:20 PM3/21/18
to Jenkins Dev
On Wed, Mar 21, 2018 at 3:53 PM, Ullrich Hafner
<ullrich...@gmail.com> wrote:
> Is there anything different with a dropdownDescriptorSelector?

No, it should work.

Ullrich Hafner

unread,
Mar 22, 2018, 7:05:57 PM3/22/18
to Jenkins Developers
Ok, thanks. I created an issue: JENKINS-50355. Maybe the problem is that the views are in different plugins and are loaded by different class loaders...
> --
> 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/CANfRfr1MAavT6qERsd7MbgqertN91wxecedYiw0MUZm%2BdUAYyg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

Jesse Glick

unread,
Mar 23, 2018, 10:26:02 AM3/23/18
to Jenkins Dev
On Thu, Mar 22, 2018 at 7:05 PM, Ullrich Hafner
<ullrich...@gmail.com> wrote:
> I created an issue: JENKINS-50355.

Most likely some typo or other bug in your plugin code, but hard to
know offhand. If there a simple way to reproduce this problem locally,
state that in the issue.

> Maybe the problem is that the views are in different plugins and are loaded by different class loaders...

Should not matter.

Ullrich Hafner

unread,
Feb 14, 2019, 5:55:50 PM2/14/19
to Jenkins Developers
I finally managed it to get it fixed (at least in my plugin). I think there still I a bug in Stapler here:

If I define the validation method using:
public FormValidation doCheckHighThreshold(@QueryParameter final int highThreshold,
@QueryParameter final int normalThreshold) {
return VALIDATION.validateHigh(highThreshold, normalThreshold);
}
then in the generated HTML the attribute checkdependson is empty:

<input checkdependson="" default="50" checkurl="/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Model/pipeline-syntax/descriptorByName/cpd/checkHighThreshold" name="_.highThreshold" type="text" class="setting-input validated  " value="50">

If I rather use 
public FormValidation doCheckHighThreshold(@QueryParameter(value = "highThreshold") final int highThreshold,
@QueryParameter(value = "normalThreshold") final int normalThreshold) {
return VALIDATION.validateHigh(highThreshold, normalThreshold);
}
Then in the generated HTML the attribute checkdependson is correct:

<input checkdependson="highThreshold normalThreshold" default="50" checkurl="/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Model/pipeline-syntax/descriptorByName/cpd/checkHighThreshold" name="_.highThreshold" type="number" class="setting-input validated " value="50">

From the documentation of @QueryParameter: if value is not given, then the name of the parameter should be used.

--
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.
signature.asc

Jesse Glick

unread,
Feb 14, 2019, 11:05:30 PM2/14/19
to Jenkins Dev
On Thu, Feb 14, 2019 at 5:55 PM Ullrich Hafner <ullrich...@gmail.com> wrote:
> I think there still I a bug in Stapler here

Does look that way. Please file it, and of course if you can track
down the cause a PR would be great.

The only thing unusual I see about your example is the use of `int`,
where most check methods would be accepting `String`s.

Ullrich Hafner

unread,
Feb 15, 2019, 4:57:32 AM2/15/19
to Jenkins Developers

Am 15.02.2019 um 05:05 schrieb Jesse Glick <jgl...@cloudbees.com>:

On Thu, Feb 14, 2019 at 5:55 PM Ullrich Hafner <ullrich...@gmail.com> wrote:
I think there still I a bug in Stapler here

Does look that way. Please file it, and of course if you can track
down the cause a PR would be great.


(Is there no component for Stapler).

I found the root cause now as well. Stapler does not detect the parameter names since the validation methods are part of a non/public abstract class. There should be some warning or error printed by Stapler. 
Where is this part of the code located? 


The only thing unusual I see about your example is the use of `int`,
where most check methods would be accepting `String`s.

--
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.
signature.asc
Reply all
Reply to author
Forward
0 new messages