How does Hudson know
to get the content from
this file and display it as
help content for the field?
The trick is in the name
of the file. By convention,
Hudson looks for a specific filename in the same
folder that contains the
config file. The name of
the file should be help-
{fieldName}.html.
In the config.xml file we
have the 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">
<!--Creates a text field that shows the value of the "name" property.
When submitted, it will be passed to the corresponding constructor parameter.
-->
<f:entry title="Name" field="name">
<f:textbox />
</f:entry>
</j:jelly>
COMMUNITY
JAVA IN ACTION
See all listings as text
Figure 2
■ ■ textbox renders a simple HTML text
field whose value will be sent back to
the server.
<f:entry title="Name"
field="name">
<f:textbox />
</f:entry>
Understanding the UI Rendering
Let’s take a closer look at how the UI is
rendered from the Jelly file. In Part 1 of
this series, we created a Hudson project
called TestProject. Open the TestProject
job configuration page by clicking the
Configure link. Scroll down to the build
section and view the Say Hello World
builder and its configuration. Click the
Help button (“?”) on the right side of the
text box. It displays online help text, as
shown in Figure 1.
Let’s find out where this help text
comes from. The content of config
.jelly has no such help text. Once again,
convention comes into play. The folder
containing the config file also has a file
named help-name.html. Open the file
using an editor and notice that it contains
the exact help text shown in Figure 1.
field="name" indicates that the text
box should be used as an entry field with
the name Name. So, based on convention, the help text for that field should
exist in a file named help-name.html.
The content of the help-name.html
file is pure HTML. You can include
images, text, and hyperlinks in the
content to emphasize and enhance your
help text. As mentioned in the example
help text in Figure 1, if
you want to use information from Hudson model
objects, you should have
Jelly content in the field
help file and the file
extension should be .jelly
instead of .html. Listing 2
shows an example file
called help-name.jelly.
When Hudson is stopped and
restarted with the above Jelly help file,
clicking the Help button for the same text
field displays the text shown in Figure 2.
Note that ${app.displayName} is
replaced with Hudson, which is the name
of the application.
UI and Model Object Interaction
Now let’s see how the UI interacts with
Hudson model objects. HelloBuilder is a
Hudson model object. It encapsulates
data. The UI can interact with this model
to get and display its data, get information from the user via fields in the UI,
and update the model data.
The help file, help-
name.jelly, contains a
JEXL expression ${app
.displayName}. When the
server side of the Hudson
application receives the
request to render the job
configuration page, it
includes both the snip-
pets config.jelly and help-
name.jelly in the job configuration page,
which itself is another Jelly file.
ABOUT US
The content of the
help-name.html file is
pure HTML; you can
include images, text,
and hyperlinks.