public class FormFillFailure extends IOException implements org.kohsuke.stapler.HttpResponse
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); } } }
Modifier and Type | Method and Description |
---|---|
static FormFillFailure |
errorWithValue(hudson.util.FormValidation fv,
String value)
Calls
errorWithValue(String, String) with the message from the
specified FormValidation . |
static FormFillFailure |
errorWithValue(String message,
String value)
Creates a new
FormFillFailure 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, or
null if the form
control value was not encoded by errorWithValue(String, String) . |
static boolean |
isError(String formControlValue)
True if the form control value was encoded by
errorWithValue(String, String) . |
String |
toString() |
static hudson.util.FormValidation |
validateRequired(String formControlValue)
Extension of
JenkinsUtil.validateRequired(java.lang.String) that always fails if
the form control value was encoded by
errorWithValue(String, String) . |
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
public static FormFillFailure errorWithValue(String message, String value)
FormFillFailure
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.message
- the error messagevalue
- the value when the error occurredFormFillFailure
createdIllegalArgumentException
- if the value was already encoded by this
methodgetErrorValue(java.lang.String)
public static FormFillFailure errorWithValue(hudson.util.FormValidation fv, String value)
errorWithValue(String, String)
with the message from the
specified FormValidation
. The kind must be
FormValidation.Kind.ERROR
.fv
- the cause of the failurevalue
- the value when the error occurredFormFillFailure
createdIllegalArgumentException
- if the kind is not ERRORIllegalArgumentException
- if the value was already encoded by
errorWithValue(String, String)
getErrorValue(java.lang.String)
public static boolean isError(String formControlValue)
errorWithValue(String, String)
.formControlValue
- form control valuetrue
if the form control value was encoded by
errorWithValue(String, String)
public static String getErrorValue(String formControlValue)
null
if the form
control value was not encoded by errorWithValue(String, String)
.formControlValue
- form control valuenull
if the form
control value was not encoded by errorWithValue(String, String)
public static hudson.util.FormValidation validateRequired(String formControlValue)
JenkinsUtil.validateRequired(java.lang.String)
that always fails if
the form control value was encoded by
errorWithValue(String, String)
.formControlValue
- form control valueFormValidation
object createdpublic void generateResponse(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, Object node) throws IOException, javax.servlet.ServletException
generateResponse
in interface org.kohsuke.stapler.HttpResponse
IOException
javax.servlet.ServletException
Copyright © 2016–2018. All rights reserved.