Class FormValidation
- All Implemented Interfaces:
- Serializable,- org.kohsuke.stapler.HttpResponse
 Use one of the factory methods to create an instance, then return it from your doCheckXyz
 method. (Via HttpResponse, the returned object will render the result into StaplerResponse2.)
 This way of designing form field validation allows you to reuse doCheckXyz() methods
 programmatically as well (by using kind.
 
 For typical validation needs, this class offers a number of validateXXX(...) methods, such as
 validateExecutable(String). FilePath also has a number of validateXXX(...) methods
 that you may be able to reuse.
 
 Also see doCheckCvsRoot in CVSSCM as an example.
 
 This class extends IOException so that it can be thrown from a method. This allows one to reuse
 the checking logic as a part of the real computation, such as:
 
 String getAntVersion(File antHome) throws FormValidation {
    if (!antHome.isDirectory())
        throw FormValidation.error(antHome+" doesn't look like a home directory");
    ...
    return IOUtils.toString(new File(antHome,"version"));
 }
 ...
 public FormValidation doCheckAntVersion(@QueryParameter String f) {
     try {
         return ok(getAntVersion(new File(f)));
     } catch (FormValidation f) {
         return f;
     }
 }
 ...
 public void perform(...) {
     String version = getAntVersion(antHome);
     ...
 }
 - Since:
- 1.294
- Author:
- Kohsuke Kawaguchi
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classBuilds up the check URL for the client-side JavaScript to call back.static classPerforms an application-specific validation on the given file.static enumIndicates the kind of result.static classConvenient base class for checking the validity of URLs.
- 
Field SummaryFields
- 
Method SummaryModifier and TypeMethodDescriptionstatic FormValidationaggregate(Collection<FormValidation> validations) Aggregate multiple validations into one.static FormValidationSends out a string error message that indicates an error.static FormValidationSends out a string error message that indicates an error, by formatting it withString.format(String, Object[])static FormValidationSends out a string error message, with optional "show details" link that expands to the full stack trace.static FormValidationstatic FormValidationerrorWithMarkup(String message) Sends out an HTML fragment that indicates an error.voidgenerateResponse(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object node) static FormValidationok()static FormValidationstatic FormValidationstatic FormValidationokWithMarkup(String message) abstract Stringstatic FormValidationrespond(FormValidation.Kind kind, String html) Sends out an arbitrary HTML fragment as the output.protected voidSends out an arbitrary HTML fragment as the output.static FormValidationvalidateBase64(String value, boolean allowWhitespace, boolean allowEmpty, String errorMessage) Makes sure that the given string is a base64 encoded text.static FormValidationvalidateExecutable(String exe) Makes sure that the given string points to an executable file.static FormValidationvalidateExecutable(String exe, FormValidation.FileValidator exeValidator) Makes sure that the given string points to an executable file.static FormValidationvalidateIntegerInRange(String value, int lower, int upper) Make sure that the given string is an integer in the range specified by the lower and upper bounds (both inclusive)static FormValidationvalidateNonNegativeInteger(String value) Makes sure that the given string is a non-negative integer.static FormValidationvalidatePositiveInteger(String value) Makes sure that the given string is a positive integer.static FormValidationvalidateRequired(String value) Makes sure that the given string is not null or empty.static FormValidationstatic FormValidationstatic FormValidationstatic FormValidationstatic FormValidationwarningWithMarkup(String message) Methods inherited from class java.lang.ThrowableaddSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.kohsuke.stapler.HttpResponsegenerateResponse
- 
Field Details- 
kind
 
- 
- 
Method Details- 
errorSends out a string error message that indicates an error.- Parameters:
- message- Human readable message to be sent.- error(null)can be used as- ok().
 
- 
warning
- 
ok
- 
ok
- 
errorSends out a string error message that indicates an error, by formatting it withString.format(String, Object[])
- 
warning
- 
ok
- 
errorSends out a string error message, with optional "show details" link that expands to the full stack trace.Use this with caution, so that anonymous users do not gain too much insights into the state of the system, as error stack trace often reveals a lot of information. Consider if a check operation needs to be exposed to everyone or just those who have higher access to job/hudson/etc. 
- 
warning
- 
error
- 
warning
- 
aggregateAggregate multiple validations into one.- Returns:
- Validation of the least successful kind aggregating all child messages.
- Since:
- 1.590
 
- 
errorWithMarkupSends out an HTML fragment that indicates an error.This method must be used with care to avoid cross-site scripting attack. - Parameters:
- message- Human readable message to be sent.- error(null)can be used as- ok().
 
- 
warningWithMarkup
- 
okWithMarkup
- 
respondSends out an arbitrary HTML fragment as the output.
- 
validateExecutableMakes sure that the given string points to an executable file.
- 
validateExecutablepublic static FormValidation validateExecutable(String exe, FormValidation.FileValidator exeValidator) Makes sure that the given string points to an executable file.- Parameters:
- exeValidator- If the validation process discovers a valid executable program on the given path, the specified- FormValidation.FileValidatorcan perform additional checks (such as making sure that it has the right version, etc.)
 
- 
validateNonNegativeIntegerMakes sure that the given string is a non-negative integer.
- 
validateIntegerInRangeMake sure that the given string is an integer in the range specified by the lower and upper bounds (both inclusive)- Parameters:
- value- the value to check
- lower- the lower bound (inclusive)
- upper- the upper bound (inclusive)
- Since:
- 2.104
 
- 
validatePositiveIntegerMakes sure that the given string is a positive integer.
- 
validateRequiredMakes sure that the given string is not null or empty.
- 
validateBase64public static FormValidation validateBase64(String value, boolean allowWhitespace, boolean allowEmpty, String errorMessage) Makes sure that the given string is a base64 encoded text.- Parameters:
- allowWhitespace- if you allow whitespace (CR,LF,etc) in base64 encoding
- allowEmpty- Is empty string allowed?
- errorMessage- Error message.
- Since:
- 1.305
 
- 
generateResponsepublic void generateResponse(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object node) throws IOException, jakarta.servlet.ServletException - Specified by:
- generateResponsein interface- org.kohsuke.stapler.HttpResponse
- Throws:
- IOException
- jakarta.servlet.ServletException
 
- 
renderHtml
- 
respondprotected void respond(org.kohsuke.stapler.StaplerResponse2 rsp, String html) throws IOException, jakarta.servlet.ServletException Sends out an arbitrary HTML fragment as the output.- Throws:
- IOException
- jakarta.servlet.ServletException
 
 
-