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

Standard form control for string collections

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      There is not a great way in Jenkins databinding to handle String[]-valued properties. The general best practice is to make the property name as understood by Stapler (data binding) match the property name as understood by XStream (serial form), and for the type of both to be natural (a collection of some kind rather than a text blob). This makes for more consistent and predictable interaction with ways of defining job configuration other than the web UI. This tends to matter for the Workflow plugins (Describable objects instantiated as part of Step configuration from the Groovy DSL); Job DSL plugin; YAML Project plugin; etc.

      This commit gives an example of how you can make these align, even using the standard textarea.jelly control. The trick is to override Descriptor.newInstance. This is awkward though, and prevents you from using automatic databinding for other properties of the same class.

      It would be preferable to have a standard form control dedicated to representing a list of strings, probably rendered as a textarea (split on newlines and whitespace trimmed), though a series of textboxes with Add/Remove buttons is also an option. The representation created by buildFormTree should be a JSON array, which I believe Stapler already knows how to bind to Java arrays and/or lists; and FormChecker would ideally let you use a collection type in @QueryParameter for doCheck* methods as well. (Using a Set<String> as the property type is dubious, because duplicates will be silently deleted when the form is saved. Perhaps better to use a FormValidation warning to alert the user if duplicates are unwanted for the particular property.)

        Attachments

          Issue Links

            Activity

            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java
            http://jenkins-ci.org/commit/workflow-plugin/df1825c211c5c6be0875c9d4c334c9f7aed3d8ba
            Log:
            JENKINS-27901 Noting.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java http://jenkins-ci.org/commit/workflow-plugin/df1825c211c5c6be0875c9d4c334c9f7aed3d8ba Log: JENKINS-27901 Noting.
            Hide
            domi Dominik Bartholdi added a comment - - edited

            this would really be great!
            Now that more and more plugins try to integrate/support with the workflow plugin, we start to discover the very strange object structures generated (just to satisfy the form binding) - this would at least allow to simplify some of it.

            Show
            domi Dominik Bartholdi added a comment - - edited this would really be great! Now that more and more plugins try to integrate/support with the workflow plugin, we start to discover the very strange object structures generated (just to satisfy the form binding) - this would at least allow to simplify some of it.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java
            http://jenkins-ci.org/commit/workflow-basic-steps-plugin/2bffe36734ffdaba8cc85071b53c4d7d7bf7b509
            Log:
            JENKINS-27901 Noting.
            Originally-Committed-As: df1825c211c5c6be0875c9d4c334c9f7aed3d8ba

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java http://jenkins-ci.org/commit/workflow-basic-steps-plugin/2bffe36734ffdaba8cc85071b53c4d7d7bf7b509 Log: JENKINS-27901 Noting. Originally-Committed-As: df1825c211c5c6be0875c9d4c334c9f7aed3d8ba
            Hide
            jglick Jesse Glick added a comment -

            Noting Stapler PR 134 which touches on related code.

            Show
            jglick Jesse Glick added a comment - Noting Stapler PR 134 which touches on related code.

              People

              • Assignee:
                Unassigned
                Reporter:
                jglick Jesse Glick
              • Votes:
                7 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated: