This tag creates a right-aligned button for performing server-side validation. It is suitable for situations where the validation depends on the values of multiple input fields, such as credential check that uses both username and password.
<f:entry title="${%Access Key ID}">
<f:textbox field="accessId" />
</f:entry>
<f:entry title="${%Secret Access Key}">
<f:password field="secretKey" />
</f:entry>
<f:validateButton
title="${%Test Connection}" progress="${%Testing...}"
method="testConnection" with="secretKey,accessId" />
The title
attribute is used to determine the text written on the button. The progress
attribute determines the message displayed while the server-side validation is in progress. The method
attribute specifies the server-side method invoked by this button; this follows the stapler name mangling convention, so for example method="testConnection"
will invoke the doTestConnection
method. This method needs to be on the Descriptor class that owns this form fragment.
The with
attribute specifies the input fields sent to the server for the validation. They are matched against the field
attribute or the name
attribute of other input controls. The values of the nearest input fields above the <f:validateButton/>
are sent to the server, so this means the button has to come after the input fields. Multiple fields can be specified by using ','.
On the server side, this tag invokes the standard "do"-style method like this:
@POST
public FormValidation doTestConnection(@QueryParameter("accessId") final String accessId,
@QueryParameter("secretKey") final String secretKey,
@AncestorInPath Job job) throws IOException, ServletException {
try {
if (job == null) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
} else {
job.checkPermission(Item.CONFIGURE);
}
... do some tests ...
return FormValidation.ok("Success");
} catch (EC2Exception e) {
return FormValidation.error("Client error : "+e.getMessage());
}
}
The doTestConnection method contains the validation logic. In the end, this method has to call either FormValidation.ok
, .warning
, or .error method. Depending on which method you use, the appropriate HTML will be rendered on the client side to indicate the status to the user.