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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Oliver Gondža-2
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/bde36da3-0ed4-d02a-7760-1e54d42dcbf8%40gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

Daniel Beck-2

On Wed, Jan 6, 2021 at 11:53 AM Oliver Gondža <[hidden email]> wrote:
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

--
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 [hidden email].
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.

 


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAMo7PtKu5GYVjbTbTJpc_ugqkt92Ev_9%2BhKcrGRCRgqi8U%3Da4g%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

Jesse Glick-4
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr2AdHn7bGRdsWRPsnLChi9bvDdgAa_nrhHodzb2SBOUVQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

Oliver Gondža-2
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!
On Wednesday, January 6, 2021 at 7:57:36 PM UTC+1 Jesse Glick wrote:
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/6416a171-393b-4d5d-ba41-09eed1602ff2n%40googlegroups.com.