jelly - represent a recursive model

242 views
Skip to first unread message

novamine118

unread,
Mar 5, 2014, 1:03:15 AM3/5/14
to jenkin...@googlegroups.com
I would like the ability to store a list of "Person"s, where is a Person has a name and a List of "Person"s I've spent hours on this and cannot figure out what my jelly file should look like. I'm currently running into stackoverflow errors when jenkins tries to render my script.
Is there anyway to achieve this? here is my code (essentially a derivative of HelloWorldBuilder):
===========HelloWorldBuilder config.jetty===========
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
  <f:entry title="Person Name" field="name">
    <f:textbox />
  </f:entry>
  <f:entry title="Children">
    <f:repeatableProperty field="children"/>
  </f:entry>
</j:jelly>
===========end root config.jetty===========
===========child config.jetty===========
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="Child Name" field="name">
    <f:textbox />
  </f:entry>
  <f:entry title="Children">
    <f:repeatableProperty field="children"/>
  </f:entry>
</j:jelly>
===========end child config.jetty===========
===========Child class=============
public class Child extends AbstractDescribableImpl<Child>{
    public String name;
    public List<Child> children;
    
    @DataBoundConstructor
  public Child(String name, List<Child> children) {
      this.name=name;
      this.children=children;
  }
    
    @Extension
  public static class DescriptorImpl extends Descriptor<Child> {
        @Override
    public String getDisplayName() {
      return "";
    }
    }
    
}
==========end child class===========
root class is the same as the HelloWorldBuilder, with this instead:
    public String name;
    public List<Child> children;
    // Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
    @DataBoundConstructor
    public HelloWorldBuilder(String name, List<Child> children) {
        this.name = name;
        this.children = children;
    }

Jesse Glick

unread,
Mar 5, 2014, 1:27:38 AM3/5/14
to jenkin...@googlegroups.com
On Tue, Mar 4, 2014 at 10:03 PM, novamine118 <xavie...@gmail.com> wrote:
> I'm currently running into stackoverflow errors when jenkins tries to render my script.

f:repeatable creates an invisible prototype block
(class="repeated-chunk to-be-removed") which it copies and makes
visible when you click the Add button. I suspect the generation of the
HTML for the prototype is triggering recursion.

Some other form controls, notably f:hetero-list, use l:ajax to load
the config of children only on demand, which would presumably break
the cycle. I wonder if making f:repeatableProperty wrap its st:include
in l:renderOnDemand + l:ajax would do the same for homogeneous lists.
If so, you could work around the problem without patching Jenkins by
inlining f:repeatableProperty into your config page (it is short) and
making that change. Not for the weak of heart. If my guess is right,
probably f:repeatableProperty should be fixed in Jenkins core so it
works out of the box with recursive data types.

BTW the trunk version of the documentation for f:repeatableProperty
notes that you usually need to add your own f:repeatableDeleteButton.
This was probably not documented before because not many people seem
to use this tag yet.

novamine118

unread,
Mar 5, 2014, 10:51:22 AM3/5/14
to jenkin...@googlegroups.com
Thanks for the quick reply. I'll try out the suggestions you mentioned this weekend and let you know what I end up choosing.

Thanks again!

novamine118 .

unread,
Mar 6, 2014, 12:38:21 AM3/6/14
to jenkin...@googlegroups.com
Yep, I used the f:repeatableHeteroProperty tag to achieve the recursive nesting. I essentially copied what was in the configure-entries.jelly regarding adding columns:
<f:section title="${%Columns}">
    <f:block>
      <f:repeatableHeteroProperty field="columns" hasHeader="true" addCaption="${%Add column}"/>
    </f:block>
  </f:section>

Being a week old in jenkins plugin dev, I can live with this UI.

Thanks,
Xavier


On Wed, Mar 5, 2014 at 10:51 AM, novamine118 <xavie...@gmail.com> wrote:
Thanks for the quick reply. I'll try out the suggestions you mentioned this weekend and let you know what I end up choosing.

Thanks again!

--
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/XHvOM5Co2Mk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages