Maybe I'm not looking in the right places or I just don't understand the 
code but I cannot see how to get an optionalProperty to work.  The only 
example I can find this the ui-samples-plugin which has an overly 
complicated example that I cannot follow.

 
1. Do you have any advice on how to search existing plugin code for 
optionalProperty usage?  Google isn't that helpful...

2. Can you either:

   - point me at a plugin that has a simple implementation that I could use 
   to adapt the following code 

or


   - suggest what changes I need to make to convert the following 
   optionalBlock to an optionalProperty? 

  
<https://lh3.googleusercontent.com/-0EKgnAp123U/WKVwHpxPUmI/AAAAAAAAAAg/AdxdELUfOd8jxAyBfP2rTJy65P_P20iHgCLcB/s1600/shot.png>


 

<file:///C:/Users/andre/AppData/Local/Packages/microsoft.windowscommunicationsapps_8wekyb3d8bbwe/TempState/msohtmlclipclip_image001.png>*Jelly
 
Snippet*

<f:optionalBlock title="Set Build Variables in BuildMaster" 
field="setBuildVariables" >
    <f:entry title="Copy Previous Build's Variables" 
field="preserveVariables" >
        <f:checkbox default="false" />
    </f:entry>
    <f:entry title="Variables" field="variables" >
        <f:expandableTextbox /> 
    </f:entry>  
</f:optionalBlock>

 

*Class Snippet*

@DataBoundSetter 
public final void setSetBuildVariables(SetBuildVariables setBuildVariables) 
{
    if (setBuildVariables != null) {
        this.setBuildVariables = true;
        this.preserveVariables = setBuildVariables.preserveVariables;
        this.variables = setBuildVariables.variables;
    } else {
        this.setBuildVariables = false;
        this.preserveVariables = false;
        this.variables = null;
    }
}
 
public static final class SetBuildVariables {
    private final boolean preserveVariables;
    private final String variables;

    @DataBoundConstructor 
    public SetBuildVariables(boolean preserveVariables, String variables) {
        this.preserveVariables = preserveVariables;
        this.variables = variables;
    }
}

 

Thanks in advance

  Andrew


On Thursday, January 19, 2017 at 5:13:37 AM UTC+13, Jesse Glick wrote:
>
> On Tue, Jan 17, 2017 at 7:55 PM,  <andrew...@xtra.co.nz <javascript:>> 
> wrote: 
> > When updating a plugin to support pipeline script, how do I handle an 
> > optionalBlock section? 
>
> Do not use `f:optionalBlock`. This is a low-level control. Do not 
> refer to `JSONObject` either. All this is old-style deprecated form 
> binding. 
>
> Use a high-level control like `f:optionalProperty` for nullable 
> structs (`ui-samples-plugin` has an example), or simple independent 
> `f:checkbox`es for `boolean` properties (`doCheck*` form validation 
> can reject invalid combinations). 
>
> Also use `@DataBoundSetter` for any property with a plausible default. 
>

-- 
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 jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/e7fe9147-aeab-4b9e-9e34-1b63b1f87d2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to