Is there a way to simplify this further? It strikes me as a basic pattern for anybody implementing a JobProperty...
I currently have the following jelly for a JobProperty
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:optionalBlock name="useTemplate" title="${%Use another job as a template}" checked="${instance != null}" inline="true">
<f:entry field="templateJobName" ...
Notes:
* uses existence of the property to indicate "checked".
* use of "inline" to avoid useTemplate becoming a container of the rest of the form.
But it still requires a custom Descriptor.newInstance:
@Extension
public static class DescriptorImpl extends JobPropertyDescriptor {
@Override
public JobProperty<?> newInstance(StaplerRequest request, JSONObject formData) throws FormException {
return formData.has("useTemplate")?request.bindJSON(TemplateImplementationProperty.class, formData):null;
}