Data binding: Bind repeatable list of textboxes into List<String>

26 views
Skip to first unread message

Oliver Gondža

unread,
Jan 6, 2021, 5:54:05 AM1/6/21
to jenkin...@googlegroups.com
Hey, I am struggling with something supposedly simple. I need to get a
list of strings from user through both UI and JCasC.

In UI, I use `f:repeatable > f:textbox`, that unfortunately produces a
bit clumsy json structure of `"foo": [ {"name": "value 1"},
{"name": "value b"}, ... ]`. For databinding only, this is hidden and
can be read through a dummy data-bound class with field `String name` so
I can consume `List<Dummy>` and unwrap the strings manually. However,
this breaks the desired JCasC semantics of:

```
foo:
- one
- two
```

I ended up overriding `GlobalConfiguration#configure` to massage the
Json during form submission only to make it match the straightforward
type of `List<String>` that also works for JCasC. That, of course, is ugly.

Is there a more elegant way to read list of string inputs and have it
bound to `List<String>`?

Thanks!
--
oliver

Daniel Beck

unread,
Jan 6, 2021, 6:46:30 AM1/6/21
to JenkinsCI Developers

--
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/bde36da3-0ed4-d02a-7760-1e54d42dcbf8%40gmail.com.


--

Daniel Beck
Senior Software Engineer
CloudBees, Inc.

 


Jesse Glick

unread,
Jan 6, 2021, 1:57:36 PM1/6/21
to Jenkins Dev
Note that `CustomDescribableModel` was intended to help with this sort of case (`String` → `List<String>` and vice-versa) but AFAIK is not yet honored by `configuration-as-code`, which does not use `structs` APIs for its introspection.

ogondza

unread,
Jan 6, 2021, 4:34:11 PM1/6/21
to Jenkins Developers
Thanks for confirmation, folks. The issue have pointed me to using textarea to represent the list of strings making my life a whole lot simpler!
Reply all
Reply to author
Forward
0 new messages