Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-12802

Initial select box validation fails when default value is provided.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: core
    • Environment:
      Jenkins version 1.451.
      Jenkins run through mvn hpi:run.
      See system info in attachment for further information.
      Browser: Google Chrome 17 and Firefox 10
    • Similar Issues:

      Description

      When defining a select box like this:

      <f:entry title="Version Control System type"
              field="vcs">
          <f:select/>
      </f:entry>
      

      and validating the value through a

      int i = 0;
      public FormValidation doCheckVcs(@QueryParameter String value) {
          
          System.out.println(i + ": value: " + value);
          i++;
          try {
              VersionControlSystem.valueOf(value);
              return FormValidation.ok();
          } catch (IllegalArgumentException ex) {
              return FormValidation.error("Please select one of the Version Control Systems.");
          }
      }
      

      method, it can be observed that the validation method is called two times when opening the configuration menu (http://localhost:8080/configure). The first time, the correct default value, i.e., the selected item's value, is passed to the validation method. The second time, no data is passed in (see following code listing for output).

      0: value: MERCURIAL
      1: value: 
      

      The code is additionally available on GitHub:
      Descriptor: https://github.com/bripkens/janus-plugin/blob/389833439d11cc4daf5666c1ac7fb98ecad28471/src/main/java/de/codecentric/janus/plugin/Root.java
      Jelly: https://github.com/bripkens/janus-plugin/blob/389833439d11cc4daf5666c1ac7fb98ecad28471/src/main/resources/de/codecentric/janus/plugin/Root/global.jelly

      Data is provided in the following way:

      public ListBoxModel doFillVcsItems() {
          ListBoxModel m = new ListBoxModel();
          m.add("Please select", "");
      
          for (VersionControlSystem vcs : VersionControlSystem.values()) {
              if (this.vcs == vcs) {
                  m.add(new ListBoxModel.Option(vcs.name(), vcs.name(),
                          true));
              } else {
                  m.add(vcs.name());
              }
              
          }
      
          return m;
      }
      

        Attachments

          Activity

          Hide
          bripkens Ben Ripkens added a comment -

          I should note that the validation is done two times for a single request. The second of which fails due to the empty string.

          Show
          bripkens Ben Ripkens added a comment - I should note that the validation is done two times for a single request. The second of which fails due to the empty string.
          Hide
          jorgenpt Jørgen Tjernø added a comment -

          Removing the (poorly name) jenkins-plugin-runtime from the component list of this bug. Jenkins-plugin-runtime deals with plugins in Ruby etc, not Java. Sorry for the confusion!

          Show
          jorgenpt Jørgen Tjernø added a comment - Removing the (poorly name) jenkins-plugin-runtime from the component list of this bug. Jenkins-plugin-runtime deals with plugins in Ruby etc, not Java. Sorry for the confusion!

            People

            • Assignee:
              Unassigned
              Reporter:
              bripkens Ben Ripkens
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: