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
public class FormFillFailure extends IOException implements org.kohsuke.stapler.HttpResponse
Helper forhudson.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:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FormFillFailure
errorWithValue(FormValidation fv, String value)
CallserrorWithValue(String, String)
with the message from the specifiedFormValidation
.static FormFillFailure
errorWithValue(String message, String value)
Creates a newFormFillFailure
with the specified message and with the specified value.void
generateResponse(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, Object node)
static String
getErrorValue(String formControlValue)
Returns the value when the error occurred, ornull
if the form control value was not encoded byerrorWithValue(String, String)
.static boolean
isError(String formControlValue)
True if the form control value was encoded byerrorWithValue(String, String)
.String
toString()
static FormValidation
validateRequired(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 Detail
-
errorWithValue
public static FormFillFailure errorWithValue(String message, String value)
Creates a newFormFillFailure
with 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
FormFillFailure
created - Throws:
IllegalArgumentException
- if the value was already encoded by this method- See Also:
getErrorValue(java.lang.String)
-
errorWithValue
public static FormFillFailure errorWithValue(FormValidation fv, String value)
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
FormFillFailure
created - Throws:
IllegalArgumentException
- if the kind is not ERRORIllegalArgumentException
- if the value was already encoded byerrorWithValue(String, String)
- See Also:
getErrorValue(java.lang.String)
-
isError
public static boolean isError(String formControlValue)
True if the form control value was encoded byerrorWithValue(String, String)
.- Parameters:
formControlValue
- form control value- Returns:
true
if the form control value was encoded byerrorWithValue(String, String)
-
getErrorValue
public static String getErrorValue(String formControlValue)
Returns the value when the error occurred, ornull
if the form control value was not encoded byerrorWithValue(String, String)
.- Parameters:
formControlValue
- form control value- Returns:
- the value when the error occurred or
null
if the form control value was not encoded byerrorWithValue(String, String)
-
validateRequired
public static FormValidation validateRequired(String formControlValue)
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
FormValidation
object created
-
generateResponse
public void generateResponse(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, Object node) throws IOException, javax.servlet.ServletException
- Specified by:
generateResponse
in interfaceorg.kohsuke.stapler.HttpResponse
- Throws:
IOException
javax.servlet.ServletException
-
-