what is f:optionalBlock in jelly - jenkins

I have seen a jelly file with f:optional block
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<j:choose>
<j:when test="${instance == null}">
<f:entry title="${%File}" field="file">
<input type="file" name="file" size="40" jsonAware="yes"/>
</f:entry>
</j:when>
<j:otherwise>
<f:invisibleEntry>
<f:textbox field="fileName"/>
</f:invisibleEntry>
<f:invisibleEntry>
<f:textbox field="secretBytes"/>
</f:invisibleEntry>
<f:optionalBlock title="${%upload(instance.fileName)}" inline="true">
<f:entry title="${%File}" field="file">
<input type="file" name="file" size="40" jsonAware="yes"/>
</f:entry>
</f:optionalBlock>
</j:otherwise>
</j:choose>
<st:include page="id-and-description" class="${descriptor.clazz}"/>
</j:jelly>
What is f:optional block doing here, i mean whats its significance here ?

Jelly code internally converts to simple HTML and JavaScript code.
<f:optionalBlock> block is used to display a checkbox. When you click on this checkbox, the fields inside the checkbox are displayed on the UI.
In your example, file parameter will be displayed on UI.
We can use inline and checked properties of <f:optional> block

Related

Jenkins SCM get parameter for validation

I am trying to write a Jenkins SCM plugin.
I need to validate the parameters (Test1, Test2).
Test1 depends upon DIR field.
Test2 depends upon DIR and Test1 fields.
Class containing Test1 & Test2 is a repeatable property. Config.jelly is following `
<f:entry title="DIR" field="Dir">
<f:textbox />
</f:entry>
<f:entry title="Variable" field="var">
<f:textbox />
</f:entry>
<f:entry>
<f:repeatableProperty field="directories" noAddButton="true" minimum="1"/>
</f:entry>
`
and Config.jelly for directories is following
<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:entry title="Test1" field="test1">
<f:textbox />
</f:entry>
<f:entry title="Test2" field="test2">
<f:textbox />
</f:entry>
<f:entry>
<div align="right">
<input type="button" value="${%Add more workareas}..." class="repeatable-add show-if-last"/>
<input type="button" value="${%Delete}" class="repeatable-delete show-if-not-only" style="margin-left: 1em;"/>
</div>
How can i get value of DIR field for validating Test1? I used
public FormValidation doCheckTest1(#QueryParameter String value, #QueryParameter String Dir)
but i am getting Dir as null.
I am able to get the value of dir using #RelativePath("..")

Generated docx file is corrupted

I have a legacy Rails app, that can generate docx file. It's using just xml template, not any gem. Template is written using ERB syntax.
The problem is that generated file is marked as "corrupted" by MS Office Word, though LibreOffice on Linux opens it flawlessly. However, after recovering MS Office Word seems to open file without any content losses too.
I paste full XML template on pastebin.
While debugging I found out, that without the block, starting on the line 602, everything works fine. So I can't get, what's wrong with that particular piece of XML. I'll paste it right here for convenience
<% [task[:design_front], task[:design_back]].compact.each do |img_data| %>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Arial" w:eastAsia="Times New Roman" w:hAnsi="Arial" w:cs="Arial" />
<w:noProof />
<w:sz w:val="18" />
<w:szCs w:val="18" />
<w:lang w:eastAsia="ru-RU" />
</w:rPr>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="<%= img_data[:width] * 7400 %>" cy="<%= img_data[:height] * 7400 %>" />
<wp:effectExtent l="0" t="0" r="0" b="0" />
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="0" />
</wp:cNvGraphicFramePr>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:nvPicPr>
<pic:cNvPicPr>
<a:picLocks noChangeAspect="0" noChangeArrowheads="0" />
</pic:cNvPicPr>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="<%= img_data[:id] %>" cstate="print">
<a:extLst>
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
<a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0" />
</a:ext>
</a:extLst>
</a:blip>
</pic:blipFill>
<pic:spPr bwMode="auto">
<a:xfrm>
<a:off x="0" y="0" />
<a:ext cx="<%= img_data[:width] * 7400 %>" cy="<%= img_data[:width] * 7400 %>" />
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst />
</a:prstGeom>
<a:noFill />
<a:ln>
<a:noFill />
</a:ln>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
<% end %>
I tried to compare recovered file with my file, but I didn't see any crucial differences. I don't have that diff right now, but I can reproduce it if necessary.
Can someone show me the way? :) What am I doing wrong?
UPDATE
I tried to make corrections, suggested by Martin P., but no luck. Here is a diff between my generated file and recovered version (recovered on the right)
As far as I see, you are missing two element and some attributes.
(1) The wp:inline needs to have a wp:docPr element containing an id, name, and descr attribute.
<wp:docPr id="<% id %>" name="<% picture_name %>" descr="<% full_file_path_to_the_picture %>"/>
(2) The pic:nvPicPr element needs to have a pic:cNvPr element containing the same attributes.
<pic:cNvPr id="<% id %>" name="<% picture_name %>" descr="<% full_file_path_to_the_picture %>"/>
Of course you have to insert the missing variables (<% .. %>).
Here I marked the line where to insert the elements using comments:
<% [task[:design_front], task[:design_back]].compact.each do |img_data| %>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Arial" w:eastAsia="Times New Roman" w:hAnsi="Arial" w:cs="Arial" />
<w:noProof />
<w:sz w:val="18" />
<w:szCs w:val="18" />
<w:lang w:eastAsia="ru-RU" />
</w:rPr>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="<%= img_data[:width] * 7400 %>" cy="<%= img_data[:height] * 7400 %>" />
<wp:effectExtent l="0" t="0" r="0" b="0" />
<!-- insert wp:docPr here -->
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="0" />
</wp:cNvGraphicFramePr>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:nvPicPr>
<pic:cNvPicPr>
<!-- insert pic:cNvPr here -->
<a:picLocks noChangeAspect="0" noChangeArrowheads="0" />
</pic:cNvPicPr>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="<%= img_data[:id] %>" cstate="print">
<a:extLst>
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
<a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0" />
</a:ext>
</a:extLst>
</a:blip>
</pic:blipFill>
<pic:spPr bwMode="auto">
<a:xfrm>
<a:off x="0" y="0" />
<a:ext cx="<%= img_data[:width] * 7400 %>" cy="<%= img_data[:width] * 7400 %>" />
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst />
</a:prstGeom>
<a:noFill />
<a:ln>
<a:noFill />
</a:ln>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
<% end %>
If you look at your diff, you may see those elements added.
The fact that MS Office Word replaced the value of r:embed suggests that there was no definition of #Id="image_1" in the relationships file of this document. The relevant relationships file is probably word/_rels/document.xml.rels.
After many hours of debugging the answer is found.
The last part of this puzzle was the file [Content_Types].xml. It contained the line <Default Extension="jpeg" ContentType="image/jpeg" />, but my images have .jpg extension. I changed Extension attribute to jpg and error was gone.
However, the additions suggested by Martin P. are necessary too (how can I credit him by the way?), because without them the resulting file remains corrupted, but with an another error message.
Thanks to everybody, who tried to help me. I hope, this answer will help someone in the future.

How could I build a search application using XForms

I working on a search application using XForms standards. the applications searches a small xml file that contains students data. I've written the queries using XQuery and I've tried them out. queries results are fine, very fine. but when I connect them using XForms with the instance and submissions, the presentation layer(a xf:repeat table, each raw is a student) doesn't get updated at all.
I know that the queries are valid. the presentation is good but I'm not sure.
My question could please help me make a working copy of this application.
the Model is as follow
<xf:model>
<xf:action ev:event="xforms-ready">
<xf:send submission="load-data"/>
</xf:action>
<xf:instance xmlns="" id="studInstance">
<students>
<student>
<idStudent/>
<Name/>
<LastName/>
<Address/>
</student>
</students>
</xf:instance>
<xf:instance xmlns="" id="search">
<parameters>
<query/>
<field>Name</field>
</parameters>
</xf:instance>
<xf:submission id="load-data" method="get" serialization="none" action="modules/load.xql" replace="instance" instance="studInstance">
<xf:message ev:event="xforms-submit-error" level="ephemeral">Load operation failed </xf:message>
<xf:message ev:event="xforms-submit-done" level="ephemeral">Load operation Succeeded </xf:message>
</xf:submission>
<xf:submission id="search" action="modules/search.xql" method="post" serialization="none" ref="instance('search')" targetref="instance('studInstance')" replace="instance">
<xf:message ev:event="xforms-submit-error" level="ephemeral">Search operation failed </xf:message>
</xf:submission>
</xf:model>
the result would be bind-ed to repeat section here:
<xf:group>
<xf:repeat instance="studInstance" nodeset="/students/student">
<tr>
<td>
<xf:output ref="idStudent"/>
</td>
<td>
<xf:output ref="Name"/>
</td>
<td>
<xf:output ref="LastName"/>
</td>
<td>
<xf:output ref="Address"/>
</td>
</tr>
</xf:repeat>
</xf:group>
So what's wrong with this code!
The attribute instance has no meaning in a xf:repeat. The correct way of doing what you want is using the instance function inside your XPath:
<xf:repeat nodeset="instance(studInstance)/student">

Nesting GSP tags in Grails

This no worky, the onClick handler is removed by Grails when I do a view-source on the HTML output (Grails 1.2.1) What am i missing?
I'm trying to internationalize the confirmation message displayed in the javascript
<g:actionSubmit id="deleteButton" value="Delete" action="deleteActivities" onclick="return confirm(' ${g.message(code="common.confirm.delete", args="['Activity']") } ');"/>
Try to use it as follows:
<g:actionSubmit id="deleteButton" value="Delete" action="deleteActivities" onclick="return confirm(' ${message(code: "common.confirm.delete", args: ['Activity'])} ');"/>

Change the selection state of the litstbox item when a user clicks on a button (ZK 3.6.4)

I'm working in a project with ZK 3.6.4. but I have a problem, I want to change the selection state of the litstbox item when a user clicks on a button inside the same listbox ( same listitem)., because I want to know the selectedItem. I was reading zk documentation and I can do it , but with Zk version 5.0.5+ (nonselectableTags). But I cannot change for this version for project rules. So, there are a way to emulate this behavior with 3.6.4? or what kind of advices can you give me to do this? I really appreciate your help.
Here the code that I have.
<listbox
id="listDocAcads" mold="paging" pageSize="2"
model="#{win$composer.academicCollections}"
selectedItem="#{controller.docEntAcad}" >
<listhead>
<listheader
width="30%" label="Name" />
<listheader
width="15%" label="amount" />
<listheader
width="15%" label=" delivered?" />
<listheader
width="20%" label="Importance" />
<listheader
width="20%" label="Document" />
</listhead>
<listitem
self="#{each='docAcad'}" value="docAcad"
style="border:none;">
<listcell
label="#{docAcad.colleByProcess.oDocument.name}" />
<listcell
label="#{docAcad.colleByProcess.amount}" />
<listcell>
<spinner
width="60%" value="#{docAcad.amount}" />
</listcell>
<listcell
label="#{docAcad.colleByProcess.oImportance.name}" />
<listcell ><button id="btnUploadDocument" label="Upload"/> </listcell>
</listitem>
</listbox>
if you want to ignore button and input's u can do this.
nonselectableTags="button, input".
<listbox nonselectableTags="button, input">
<listitem><listcell><textbox/></listcell></listitem>
<listitem><listcell><button label="button"/></listcell></listitem>
<listitem><listcell><h:input xmlns:h="native"/></listcell></listitem>
<listitem><listcell><datebox/></listcell></listitem>
</listbox>
the values to nonselectableTags should be HTML tags separated by comma.
Hope this helps!

Resources