Class FormFillFailure
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.io.IOException
com.oracle.cloud.baremetal.jenkins.FormFillFailure
- All Implemented Interfaces:
Serializable,org.kohsuke.stapler.HttpResponse
Helper for
hudson.util.FormFillFailure, which was not added until
JENKINS-42443,
which was added in Jenkins 2.50. If an older version of Jenkins is being
used at runtime, then a fallback implementation is used.
Sample usage
public class TheClass {
@DataBoundConstructor
public TheClass(String theField) {
// Decode in case the control form had an encoded error.
this.theField = FormFillFailure.getErrorValue(theField);
}
public class DescriptorImpl ... {
public ListBoxModel doFillTheFieldItems(@QueryParameter String theField) throws FormFillFailure {
// Decode in case the control form had an encoded error.
theField = FormFillFailure.getErrorValue(theField);
if (...error...) {
throw FormFillFailure.error(...message..., theField);
}
// Add an empty value to require selection.
ListBoxModel model = new ListBoxModel().add("");
// Explicitly set the selected parameter in case the control form
// value had an encoded error with this value.
model.add(new ListBoxModel.Option(displayName, value, value.equals(theField)));
return model;
}
public FormValidation doCheckTheField(@QueryParameter String theField) {
// Decode in case the control form had an encoded error without
// a selected value.
return FormFillFailure.validateRequired(value);
}
}
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic FormFillFailureerrorWithValue(FormValidation fv, String value) CallserrorWithValue(String, String)with the message from the specifiedFormValidation.static FormFillFailureerrorWithValue(String message, String value) Creates a newFormFillFailurewith the specified message and with the specified value.voidgenerateResponse(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, Object node) static StringgetErrorValue(String formControlValue) Returns the value when the error occurred, ornullif the form control value was not encoded byerrorWithValue(String, String).static booleanTrue if the form control value was encoded byerrorWithValue(String, String).toString()static FormValidationvalidateRequired(String formControlValue) Extension ofJenkinsUtil.validateRequired(java.lang.String)that always fails if the form control value was encoded byerrorWithValue(String, String).Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Method Details
-
errorWithValue
Creates a newFormFillFailurewith the specified message and with the specified value. The value will be encoded in the form control value so that both the error status and original value can be determined.- Parameters:
message- the error messagevalue- the value when the error occurred- Returns:
- the
FormFillFailurecreated - Throws:
IllegalArgumentException- if the value was already encoded by this method- See Also:
-
errorWithValue
CallserrorWithValue(String, String)with the message from the specifiedFormValidation. The kind must beFormValidation.Kind.ERROR.- Parameters:
fv- the cause of the failurevalue- the value when the error occurred- Returns:
- the
FormFillFailurecreated - Throws:
IllegalArgumentException- if the kind is not ERRORIllegalArgumentException- if the value was already encoded byerrorWithValue(String, String)- See Also:
-
isError
True if the form control value was encoded byerrorWithValue(String, String).- Parameters:
formControlValue- form control value- Returns:
trueif the form control value was encoded byerrorWithValue(String, String)
-
getErrorValue
Returns the value when the error occurred, ornullif the form control value was not encoded byerrorWithValue(String, String).- Parameters:
formControlValue- form control value- Returns:
- the value when the error occurred or
nullif the form control value was not encoded byerrorWithValue(String, String)
-
validateRequired
Extension ofJenkinsUtil.validateRequired(java.lang.String)that always fails if the form control value was encoded byerrorWithValue(String, String).- Parameters:
formControlValue- form control value- Returns:
- a
FormValidationobject created
-
toString
-
generateResponse
public void generateResponse(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, Object node) throws IOException, javax.servlet.ServletException - Specified by:
generateResponsein interfaceorg.kohsuke.stapler.HttpResponse- Throws:
IOExceptionjavax.servlet.ServletException
-