Hello I'm a beginner dev in Jenkins.
I actually try to fill a list of object using the repeatable tag in the view
config.jelly.
I using codes from other plugins and people in this forum but it seems i'm
doing it the wrong way. 

I'm actually coding in the dashboard view plugin but i will soon create a
whole new plugins.

Here my code :

*Jelly code (config.jelly) :*

<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" xmlns:i="jelly:fmt">
    
    <f:entry title="test a">
        <f:repeatable var="instance" name="instances"
items="${descriptor.instances}"  noAddButton="true" minimum="1">
            

                <f:entry  title="${%Name of the line : }"
name="dashboard.testResumeStatisticsTable.labelLineName" value =
"instance.labelLineName">
                    <f:textbox />
                </f:entry>
                
        
                <f:entry title="Job : "
name="dashboard.testResumeStatisticsTable.jobName">
                    <select>
                        <j:forEach var="i" items="${it.getJobs()}">
                            <f:option selected="${i.getFullDisplayName() ==
instance.jobName}"
value="${i.getFullDisplayName()}">${i.getFullDisplayName()}</f:option>
                        </j:forEach>
                    </select>
                </f:entry>
                <f:entry>
                    <div align="right">
                        <input type="button" value="${%Add another task...}"
class="repeatable-add show-if-last" />
                        <input type="button" value="${%Delete}"
class="repeatable-delete show-if-not-only" style="margin-left: 1em;" />
                    </div>
                </f:entry>
            

        </f:repeatable>
    </f:entry>
</j:jelly>

*Main class (TestResumeStatisticsTable.java) :*

public class TestResumeStatisticsTable extends DashboardPortlet {


    private List<LineResumeTableInstance> lines;
    private static final Logger logger =
Logger.getLogger(TestResumeStatisticsTable.class.getName());

    @DataBoundConstructor
    public TestResumeStatisticsTable(String name) {
        super(name);
    }
    
  
    public void setLines(List<LineResumeTableInstance> lines){
        this.lines = lines;
    }

    public Job getJobFromName(String jobName) {
        for (Job j : getJobs()) {
            if (jobName.equals(j.getFullDisplayName())) {
                return j;
            }
        }
        return null;
    }

    public List<Job> getJobs() {
        return super.getDashboard().getJobs();
    }

    @Extension
    public static class DescriptorImpl extends Descriptor<DashboardPortlet>
{

        private List<LineResumeTableInstance> instances =  new
ArrayList<LineResumeTableInstance>();

        public DescriptorImpl() {
            load();
        }
        public List<LineResumeTableInstance> getInstances() {
            return instances;
        }
        
        public void setInstances(List<LineResumeTableInstance> instances) {
            this.instances = instances;
        }
        
        public LineResumeTableInstance getInstance(String name) {
            for(LineResumeTableInstance instance : instances) {
                if(instance.getLabelLineName().equals(name)) {
                    return instance;
                }
            }
            return null;
        }

        @Override
        public String getDisplayName() {
            return Messages.Dashboard_TestResumeStatisticsTable();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean configure(StaplerRequest req, JSONObject formData)
throws FormException {
            req.bindParameters(this, "cobertura.");
            save();
            return super.configure(req, formData);
        }

        @Override
        public TestResumeStatisticsTable newInstance(StaplerRequest req,
JSONObject formData) throws FormException {
            TestResumeStatisticsTable instance =
req.bindJSON(TestResumeStatisticsTable.class, formData);
            List<LineResumeTableInstance> lines = req
                    .bindParametersToList(LineResumeTableInstance.class,
"dashboard.testResumeStatisticsTable.");
            instance.setLines(lines);
            return instance;
        }

    }

}

*and finally The class which will be the list object
(LineResumeTableInstance.java):*

public class LineResumeTableInstance{
    
    private final String jobName;
    private final String labelLineName;
    
    @DataBoundConstructor
    public LineResumeTableInstance(String name, String labelLineName, String
jobName){
        this.labelLineName = labelLineName;
        this.jobName = jobName;
                
    }
    
    public String getLabelLineName() {
        return labelLineName;
    }

    public String getJobName() {
        return jobName;
    }
}






--
View this message in context: 
http://jenkins-ci.361315.n4.nabble.com/Fill-List-of-objects-in-a-repeatable-tag-tp4747488.html
Sent from the Jenkins dev mailing list archive at Nabble.com.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/1429176354361-4747488.post%40n4.nabble.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to