repeatableProperty in Jenkins Global Configuration

21 views
Skip to first unread message

Ullrich Hafner

unread,
Nov 12, 2019, 5:53:00 PM11/12/19
to Jenkins Developers
I have a repeatableProperty in Jenkins Global Configuration page (see https://github.com/jenkinsci/warnings-ng-plugin/pull/266).

Expanded snippet:
<f:section title="${%Warnings Next Generation Plugin Global Settings}">
<f:entry title="${%sourceDirectories.title}" description="${%sourceDirectories.description}">
<f:repeatableProperty field="sourceDirectories">
<f:entry title="">
<div align="right">
<f:repeatableDeleteButton />
</div>
</f:entry>
</f:repeatableProperty>
</f:entry>

</f:section>

(And a describable config.jelly)
<f:entry title="${%Absolute path of folder}" field="path">
<f:textbox/>
</f:entry>
I can successfully add entries and delete entries in the UI. However, if I remove the last element in the UI then the empty list ist not saved. More precisely, the data bound setter 
/**
* Sets the list of source directories to the specified elements. Previously set directories will be removed.
*
* @param sourceDirectories
* the source directories that contain the affected files
*/
@DataBoundSetter
public void setSourceDirectories(final List<SourceDirectory> sourceDirectories) {
...


Is not called if I remove all elements in the UI (it is called for 1,…,n elements). Has anyone an idea what I am making wrong? 

Jesse Glick

unread,
Nov 12, 2019, 6:27:06 PM11/12/19
to Jenkins Dev
On Tue, Nov 12, 2019 at 5:53 PM Ullrich Hafner <ullrich...@gmail.com> wrote:
> if I remove the last element in the UI then the empty list ist not saved. More precisely, the data bound setter […]

> Is not called if I remove all elements in the UI (it is called for 1,…,n elements).

This is a well-known limitation in databinding. The workaround is to override a `configSubmit` or whatever method to first null out / clear the list, then call super. Example:

https://github.com/jenkinsci/ui-samples-plugin/blob/7d0fe2b32204a7fe0ec6adb6815e65d48b0dd54e/src/main/java/jenkins/plugins/ui_samples/HeteroList.java#L81
Reply all
Reply to author
Forward
0 new messages