Jenkins 1.637 introduced OptionalJobProperty which makes this easier. Since this is very recent, note the pros/cons of choosing this as a compatible Jenkins release for a plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Choosing+Jenkins+version+to+build+against On 03.01.2016, at 19:09, Marc Carter <[email protected]> wrote: > 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; > } > > > > -- > 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/d78b27ec-3bd8-47a9-b4f9-2a20bfe2bfc5%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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/4CB3AED3-0059-4637-A546-EDD223CFA764%40beckweb.net. For more options, visit https://groups.google.com/d/optout.
