Incorrect rendering of job property

32 views
Skip to first unread message

Mads Nielsen

unread,
Mar 8, 2016, 5:31:09 AM3/8/16
to jenkin...@googlegroups.com
Hi Guyes,

I have a problem. What im trying to do is to have Jenkins render a radio-button group with mutually exclusive options in a Job property. This work fine when the job is getting configured.

But when i reload the page...i get this: 


​Even though i have not selected the File from workspace option, it still renders the block under the radio button on page load.

Here is my jelly code, what am i doing wrong? I checked that my expressions that evaluate the checked state are correct.

<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">
    <f:optionalBlock name="on" checked="${instance.on}" title="DataDog tagging" inline="true">
        <f:radioBlock title="Properties content" name="choice" checked="${instance.tagging != null}">
            <f:entry title="Properties" field="tagging">    
                <f:textarea/>
            </f:entry>            
        </f:radioBlock>   
        <f:radioBlock title="File from workspace" name="choice" checked="${instance.tagFile != null}">
            <f:entry title="File" field="tagFile">
                <f:textbox/>
            </f:entry>
        </f:radioBlock>
    </f:optionalBlock>
</j:jelly>


Best regards,
Mads
____________________________________________________________
Mads Nielsen
Consultant
m...@praqma.net
+45 50 98 18 09
Skype: inkspot
Praqma
www.praqma.com
DK: CPH, Aarhus, Allerod
NO: OSL
SE: STHLM
+45 36 PRAQMA

Robert Sandell

unread,
Mar 8, 2016, 6:04:44 AM3/8/16
to jenkin...@googlegroups.com
My guess is that instance.tagFile is no longer null because the previous form posting set the value to an empty string.

try checked="${not empty instance.tagFile}" or maybe it's the other way around (${instance.tagFile not empty}), those jexl expressions confuse me sometimes ;)

/B

--
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-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAFariusD05U9jxMLfHD%2BK7xaP40THCFTBOJSwq0H3MowXYE3nA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.

Mads Nielsen

unread,
Mar 8, 2016, 7:23:08 AM3/8/16
to jenkin...@googlegroups.com
Hi Robert,

Thanks for the reply...No dice on this one. I double checked the values and made two helper methods on my JobProperty:


  public boolean isTagFileEmpty() {
    return StringUtils.isBlank(tagFile);
  }

  public boolean isTaggingEmpty() {
    return StringUtils.isBlank(tagging);
  }

Didn't work...i still get the radioBlock rendering the second option even though it's not checked and added a couple of debug prints to the top: 


My jelly template was modified as well:

<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">
    <f:optionalBlock name="on" checked="${instance.on}" title="DataDog tagging" inline="true">
        <h3>Tag is empty: ${instance.isTaggingEmpty()} ${instance.tagging}</h3>
        <h3>File is empty: ${instance.isTagFileEmpty()} ${instance.tagFile}</h3>
        <f:radioBlock title="Properties content" name="choice" checked="${!instance.isTaggingEmpty()}">
            <f:entry title="Properties" field="tagging">    
                <f:textarea/>
            </f:entry>            
        </f:radioBlock>   
        <f:radioBlock title="File from workspace" name="choice" checked="${!instance.isTagFileEmpty()}">
            <f:entry title="File" field="tagFile">
                <f:textbox/>
            </f:entry>
        </f:radioBlock>
    </f:optionalBlock>
</j:jelly>

This is seriously annoying :P

One thing that happens...if i remove the OptionalBlock wrapping my radio blocks, it renders correctly on reload (I.e it doesn't render the elements nested under the second radio block), but i get 2 checkboxes on my jobs configure page instead of the one i want. I used EnvInject as inspiration for the template.


Any other suggestions. I think i might abandon this entirely and create descriptors/describables for my two options...just seems overly complicated for such a simple control...:/


Best regards
Mads
____________________________________________________________
Mads Nielsen
Consultant
m...@praqma.net
+45 50 98 18 09
Skype: inkspot
Praqma
www.praqma.com
DK: CPH, Aarhus, Allerod
NO: OSL
SE: STHLM
+45 36 PRAQMA

Jesse Glick

unread,
Mar 8, 2016, 6:27:03 PM3/8/16
to Jenkins Dev
On Tue, Mar 8, 2016 at 5:31 AM, Mads Nielsen <m...@praqma.net> wrote:
> <f:optionalBlock name="on" checked="${instance.on}" title="DataDog tagging" inline="true">

Have you tried `OptionalJobProperty` in newer core versions? It covers
this common use case with less boilerplate. In and of itself does not
solve your issue but might make the cause clearer.
Reply all
Reply to author
Forward
0 new messages