Re: Fill List of objects in a repeatable tag

60 views
Skip to first unread message

Safe

unread,
Apr 20, 2015, 10:02:23 AM4/20/15
to jenkin...@googlegroups.com
I did some modification maybe it's closer to the solution but still not
working

Main class :
*public List<LineResumeTableInstance> getLines() {
return lines;
}*

...

on descriptor :
*public List<LineResumeTableInstance> getLines(TestResumeStatisticsTable
instance) {
return instance.getLines();
}*

on jelly :

<f:repeatable var="instance" name="instances"
items="${descriptor.getLines(instance)}" noAddButton="true" minimum="1">






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

Safe

unread,
Apr 20, 2015, 10:02:24 AM4/20/15
to jenkin...@googlegroups.com
Solved :)

I will post the solution when I finalized it



--
View this message in context: http://jenkins-ci.361315.n4.nabble.com/Fill-List-of-objects-in-a-repeatable-tag-tp4747488p4747695.html

Safe

unread,
Apr 20, 2015, 10:02:25 AM4/20/15
to jenkin...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages