Jelly Repeatable Items default values

128 views
Skip to first unread message

Zhengyuan Shen

unread,
Jun 13, 2013, 2:51:33 PM6/13/13
to jenkin...@googlegroups.com
Can any body tell me how to set the default value of repeatable items in Jelly to the value of previously submitted forms?

Thanks
Message has been deleted
Message has been deleted

Thiago Augusto Ventura Lima

unread,
Jul 23, 2015, 6:42:45 PM7/23/15
to Jenkins Developers, esdo...@gmail.com
I know this is a really old question, but I couldn't find any answer... Any answer?

Kanstantsin Shautsou

unread,
Jul 23, 2015, 7:00:39 PM7/23/15
to Jenkins Developers, esdo...@gmail.com, t.au...@gmail.com
There is no such functionality and description sounds weird.

If you submitted data, then you don't default entries because they become real.
If you mean default when this class/ui instance firstly loads (and instance object is null) then it not implemented yet.

Could you clarify what exactly default do you expect? 

Kanstantsin Shautsou

unread,
Jul 23, 2015, 7:05:07 PM7/23/15
to jenkin...@googlegroups.com, esdo...@gmail.com, t.au...@gmail.com
Sorry, lost word.
On Jul 24, 2015, at 02:00, Kanstantsin Shautsou <kanstan...@gmail.com> wrote:

There is no such functionality and description sounds weird.

If you submitted data, then you don't need default entries because they become real.
If you mean default when this class/ui instance firstly loads (and instance object is null) then it not implemented yet.

Could you clarify what exactly default do you expect? 

On Friday, July 24, 2015 at 1:42:45 AM UTC+3, Thiago Augusto Ventura Lima wrote:
I know this is a really old question, but I couldn't find any answer... Any answer?

On Thursday, June 13, 2013 at 3:51:33 PM UTC-3, Zhengyuan Shen wrote:
Can any body tell me how to set the default value of repeatable items in Jelly to the value of previously submitted forms?

Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/T0oJMWm3MP8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/2b300ab4-e09d-430c-a87a-858c993c31b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thiago Augusto Ventura Lima

unread,
Jul 23, 2015, 7:15:13 PM7/23/15
to Jenkins Developers
First, thanks for your quick answer, Kansantsin. :)

And, yeah, I mean exactly the 2nd option.

Assume I have a setting like "List<Foo> foos", where Foo is something like

class Foo {
  public String propertyA;
  public String propertyB;
}

What I'm trying to do is to default "foos" to an "one element list", say it "[Foo('valueA', 'valueB')]", when this class is firstly loaded and there's no instance.

So, it's not implemented yet, right? Thanks anyway... :)

ps: sorry for the mixed notation pseudo-code :)
--
Thiago Lima

Kanstantsin Shautsou

unread,
Jul 23, 2015, 7:28:11 PM7/23/15
to jenkin...@googlegroups.com
On Jul 24, 2015, at 02:15, Thiago Augusto Ventura Lima <t.au...@gmail.com> wrote:

First, thanks for your quick answer, Kansantsin. :)
Good defaults is a headache in jenkins.
I just asked few days ago jglick about the same issues. And he provided one idea what can be enhanced (i plan try it but need get free time).


And, yeah, I mean exactly the 2nd option.

Assume I have a setting like "List<Foo> foos", where Foo is something like 

class Foo {
  public String propertyA;
  public String propertyB;
}
<hidden> First of all from programatically configured code view point you should provide default for fields (also don’t use public fields;). <hidden/>

What I'm trying to do is to default "foos" to an "one element list", say it "[Foo('valueA', 'valueB')]", when this class is firstly loaded and there's no instance.

So, it's not implemented yet, right? Thanks anyway... :)
I will reply and reply later. 


ps: sorry for the mixed notation pseudo-code :)
no problems

On Thu, Jul 23, 2015 at 8:00 PM Kanstantsin Shautsou <kanstan...@gmail.com> wrote:
There is no such functionality and description sounds weird.

If you submitted data, then you don't default entries because they become real.
If you mean default when this class/ui instance firstly loads (and instance object is null) then it not implemented yet.

Could you clarify what exactly default do you expect? 


On Friday, July 24, 2015 at 1:42:45 AM UTC+3, Thiago Augusto Ventura Lima wrote:
I know this is a really old question, but I couldn't find any answer... Any answer?

On Thursday, June 13, 2013 at 3:51:33 PM UTC-3, Zhengyuan Shen wrote:
Can any body tell me how to set the default value of repeatable items in Jelly to the value of previously submitted forms?

Thanks
-- 
Thiago Lima

-- 
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/T0oJMWm3MP8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.

Christopher Orr

unread,
Jul 23, 2015, 8:39:44 PM7/23/15
to jenkin...@googlegroups.com
On 24/07/15 01:15, Thiago Augusto Ventura Lima wrote:
> Assume I have a setting like "List<Foo> foos", where Foo is something like
>
> class Foo {
> public String propertyA;
> public String propertyB;
> }
>
> What I'm trying to do is to default "foos" to an "one element list", say
> it "[Foo('valueA', 'valueB')]", when this class is firstly loaded and
> there's no instance.

repeatableProperty has a "default" field, which specifies the initial
list of values for the repeatable collection, if there isn't yet an
instance.

So basically you just need to add a way of fetching that default list
from Foo.

For example, you could do something like this:

--- Inside BarPublisher.java / wherever Foo is defined ---

public static final class Foo extends AbstractDescribableImpl<Foo> {

@Exported public final String propA;
@Exported public final String propB;

@DataBoundConstructor
public Foo(String a, String b) {
this.propA = a;
this.propB = b;
}

public static Foo[] getSomeDefaults() {
return new Foo[] { new Foo("valueA", "valueB") };
}

// ...
}

---------------------------------
--- BarPublisher/config.jelly ---

<j:invokeStatic
var="myWonderfulDefaults"
className="com.example.BarPublisher$Foo"
method="getSomeDefaults" />

<f:entry title="${%List of foos}" field="foos">
<f:repeatableProperty
field="foos"
default="${myWonderfulDefaults}"
add="${%Add foo...}" />
</f:entry>

---------------------------------

Though remember that users can delete the default "Foo" that appears and
save the job anyway, or they can upload job config directly via the API etc.

So you should probably additionally check in your
builder/publisher/whatever constructor whether the collection is empty,
and if so, apply the defaults (if that's what you want).

Regards,
Chris

Jesse Glick

unread,
Jul 27, 2015, 2:49:57 PM7/27/15
to Jenkins Dev
On Thu, Jul 23, 2015 at 8:39 PM, Christopher Orr <ch...@orr.me.uk> wrote:
> repeatableProperty has a "default" field, which specifies the initial list
> of values for the repeatable collection, if there isn't yet an instance.

Unfortunately `repeatableHeteroProperty` does not. Would be a good PR.
Reply all
Reply to author
Forward
0 new messages