Cannot read property 'value' of undefined

140 views
Skip to first unread message

Oscar Serna

unread,
Feb 2, 2016, 4:08:53 AM2/2/16
to Jenkins Developers
Hi devs,

I'm working in a Jenkins plugin and I'm struggling with an issue. AFAIK in order to populate select combo using web methods the common pattern to follow is to add this type of methods in the Descriptor class, as you can see below:

public ListBoxModel doFillXXX(){
  ListBoxModel m = new ListBoxModel();
  for(){
    ... 
   m.add(displayName, name);
  }
  return  m;
}

However when the list is empty, so there is just the m object without Options I have an error in the Javascript select.js file. The error is this:

Uncaught TypeError: Cannot read property 'value' of undefined
hasChanged @select.js:46
updateListBox.onSuccess @select.js:76
config.onSuccess @select.js:32
Ajax.Request.Class.create.respondToReadyState         @prototype.js:1657
Ajax.Request.Class.create.onStateChange @prototype.js:1600
(anonymous function) @prototype.js:414


and in that line of the select.js file you can see:

Behaviour.specify("SELECT.select", 'select', 1000, function(e) {

        function hasChanged(selectEl, originalValue) {
            var firstValue = selectEl.options[0].value;
            var selectedValue = selectEl.value;
            if (originalValue == "" && selectedValue == firstValue) {
                // There was no value pre-selected but after the call to updateListBox the first value is selected by
                // default. This must not be considered a change.
                return false;
            } else {
                return originalValue != selectedValue;
            }
        };

So, it seems like not adding options to the select causes this issue. Probably I'm making some type of mistake or maybe I'm missing something. Any help will be welcome. My Jenkins version is 1.644. 

Thanks in advance.


Antonio Muñiz

unread,
Feb 2, 2016, 6:43:35 AM2/2/16
to jenkin...@googlegroups.com
Hi,

First, what do you have in the jelly file?
And second, what's the real name of doFillXXX? It should be
"doFillXXXItems", where XXX is the name of the bean property.
> --
> 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/f3f34eb7-9cf5-4963-a367-16fe52377691%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Antonio Muñiz
Software Engineer
CloudBees, Inc.

Oscar Serna

unread,
Feb 2, 2016, 6:59:42 AM2/2/16
to Jenkins Developers


Thanks for your quickly answer, below you can see what I have in my in the Jelly config.jelly file:





and in the Descriptor part:







In the next schema you can see the error:







It happens during the first two calls, the first one is a call to doFillStateItems() and just immediately after there is another call to doFillCityItems(@QueryParameter String state) but without parameters. In that case as you can see in the java code, I’m currently returning an empty ListBoxModel



Regards and thanks in advance.

Antonio Muñiz

unread,
Feb 2, 2016, 3:13:04 PM2/2/16
to jenkin...@googlegroups.com
Hi Oscar,

I don't see anything suspicious in your screenshots.
If you provide a failing example (a public repo in GH?) I can take a look.


For more options, visit https://groups.google.com/d/optout.

Oscar Serna

unread,
Feb 3, 2016, 6:13:56 AM2/3/16
to Jenkins Developers
Hi Antonio, I've just seen your answer right now. I've created a simple github repo with the code in order to allow you to reproduce the error. The repo contains no more than several files, so it's really easy to set the environment and get the error. 

Thanks in advance for your help.

Oscar Serna

unread,
Feb 3, 2016, 6:14:43 AM2/3/16
to Jenkins Developers

Oscar Serna

unread,
Feb 3, 2016, 6:55:05 AM2/3/16
to Jenkins Developers
Ey, I forgot to tell you that I saw the same problem with the ssh-agent-plugin plugin:


As you can see in the capture below, if there is no credentials configured previously, the list is empty and I see the same error:

Antonio Muñiz

unread,
Feb 4, 2016, 9:43:06 AM2/4/16
to jenkin...@googlegroups.com
Thanks for the example code. I'll take a look.

On Wed, Feb 3, 2016 at 12:55 PM, Oscar Serna <se...@elasticbox.com> wrote:
> Ey, I forgot to tell you that I saw the same problem with the
> ssh-agent-plugin plugin:
>
> https://wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin
>
> As you can see in the capture below, if there is no credentials configured
> previously, the list is empty and I see the same error:
>
>
>
>
>
> On Wednesday, February 3, 2016 at 12:14:43 PM UTC+1, Oscar Serna wrote:
>>
>> Also the URL:
>>
>> https://github.com/oserna/jenkins-plugin-example
>>
>> regards!!
>>
>> On Wednesday, February 3, 2016 at 12:13:56 PM UTC+1, Oscar Serna wrote:
>>>
>>> Hi Antonio, I've just seen your answer right now. I've created a simple
>>> github repo with the code in order to allow you to reproduce the error. The
>>> repo contains no more than several files, so it's really easy to set the
>>> environment and get the error.
>>>
>>> Thanks in advance for your help.
>>>
>>>
>>>
>>> On Tuesday, February 2, 2016 at 9:13:04 PM UTC+1, Antonio Muñiz wrote:
>>>>
>>>> Hi Oscar,
>>>>
>>>> I don't see anything suspicious in your screenshots.
>>>> If you provide a failing example (a public repo in GH?) I can take a
>>>> look.
>>>>
>>>> On Tue, Feb 2, 2016 at 12:59 PM, Oscar Serna <se...@elasticbox.com>
>>>> wrote:
>>>>>
>>>>>
>>>>> Thanks for your quickly answer, below you can see what I have in my in
>>>>> the Jelly config.jelly file:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> and in the Descriptor part:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> In the next schema you can see the error:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
> https://groups.google.com/d/msgid/jenkinsci-dev/27f3599f-0a80-485a-9153-eb5156314437%40googlegroups.com.

Oscar Serna

unread,
Feb 4, 2016, 10:05:24 AM2/4/16
to Jenkins Developers
Thanks to you for helping me, don't hesitate to ask me whatever you need...

Oscar Serna

unread,
Feb 9, 2016, 11:10:50 AM2/9/16
to Jenkins Developers
Ey, Antonio ;-) 

Did you have the opportunity to to take a look to the code? 

Thanks in advance

Antonio Muñiz

unread,
Feb 15, 2016, 4:33:26 AM2/15/16
to jenkin...@googlegroups.com
Yes, I took a look and I think there is a bug in `hasChanged` code. I'll try to fix once I have a chance.
I've created this issue to track it: https://issues.jenkins-ci.org/browse/JENKINS-32945


For more options, visit https://groups.google.com/d/optout.

Oscar Serna

unread,
Feb 15, 2016, 7:27:16 AM2/15/16
to Jenkins Developers

Thanks for your time Antonio, i’ll keep an eye on this. :-)

Antonio Muñiz

unread,
Feb 27, 2016, 8:48:19 AM2/27/16
to jenkin...@googlegroups.com
Hello Oscar,

Just filed a PR to core in order to avoid the JS error.
However the right way to implement your plugin is by adding default values to the second select box too, I filed a PR to your example showing what I mean.


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages