Class FormErrors
A do* endpoint that refuses its input builds one of these and calls
render(org.kohsuke.stapler.StaplerRequest2, org.kohsuke.stapler.StaplerResponse2, java.lang.Object): the same request is forwarded to the screen's index.jelly with HTTP 400
(the status the plain Failure page answered before, so scripted callers see no change),
and the view asks current(String) for the messages and the submitted values. Nothing
here changes state; it runs after the endpoint's permission checks.
Submitted values are read back from the request only while an instance is attached to it, i.e. only on the POST that is being refused. A GET never gets a value from its query string into a field this way, and every value is rendered through Jelly's default escaping.
form names which form on a page failed, so a page with several forms (approve and
reject both have a comment field) refills only the one that was submitted.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEndpoint-side data the view needs to rebuild the form (for example parsed parameters).booleanWhethervaluewas among the submitted values of the repeatedfield.static FormErrorscurrent()The refusal attached to this request, whatever form it is for, or an empty one.static FormErrorsThe refusal of formformon this request, or an empty one.static Stringdisplayable(String text) D-72b:textwith each character XML 1.0 cannot hold (U+0000, a lone surrogate, ...) replaced by U+FFFD, as a browser shows it.Adds a message shown next tofield; the first message for a field wins.fromService(String text, String... keywords) Files a service refusal next to the field its text is about, or above the form when no keyword matches.fromServiceStartingWith(String text, String... prefixes) AsfromService(java.lang.String, java.lang.String...), but a keyword counts only at the start of the message (case-insensitive).The message next tofield, ornull.getForm()The message above the form, ornull.booleanisEmpty()Whether anything was refused.booleanWhether the refused form is shown with the user's input (value(java.lang.String),checked(java.lang.String, java.lang.String)): something was refused and the input could be read (withoutInput()).booleanThe inverse ofisEmpty(), for Jelly.Sets the message shown above the form (one that is not about a single field).voidrender(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object it) Forwards the current request toit'sindex.jellywith HTTP 400 and this refusal attached.voidrender(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object it, String view) Asrender(StaplerRequest2, StaplerResponse2, Object), to the viewviewofit: D-66, a form submitted from a dialog is answered with the dialog's own view, so core's dialog replaces its form with the refused one (messages shown, input kept).voidrender(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object it, String view, int status) Asrender(StaplerRequest2, StaplerResponse2, Object, String)with the HTTP statusstatus(D-72: 413 for a body over the size cap).What the user submitted infield; empty when nothing is being refused.D-72: the submission is refused without its input being read (its body is over the size cap, and reading a field would parse it), so the form is shown empty:value(java.lang.String)andchecked(java.lang.String, java.lang.String)return nothing and the view may use its defaults.
-
Constructor Details
-
FormErrors
- Parameters:
form- the name of the form that was submitted (reject,create, ...)
-
-
Method Details
-
field
Adds a message shown next tofield; the first message for a field wins. -
message
Sets the message shown above the form (one that is not about a single field). -
fromService
Files a service refusal next to the field its text is about, or above the form when no keyword matches.keywordsalternates keyword and field name ("reason", "reason", "approver", "approvers"); the first keyword found in the message (case-insensitive) decides. -
fromServiceStartingWith
AsfromService(java.lang.String, java.lang.String...), but a keyword counts only at the start of the message (case-insensitive). D-72b: for messages that may quote user data further on (parameter names, for one), so a word inside the quoted data cannot misfile the message. -
attach
Endpoint-side data the view needs to rebuild the form (for example parsed parameters). -
withoutInput
D-72: the submission is refused without its input being read (its body is over the size cap, and reading a field would parse it), so the form is shown empty:value(java.lang.String)andchecked(java.lang.String, java.lang.String)return nothing and the view may use its defaults. -
isEmpty
public boolean isEmpty()Whether anything was refused. -
isPresent
public boolean isPresent()The inverse ofisEmpty(), for Jelly. -
isInputKept
public boolean isInputKept()Whether the refused form is shown with the user's input (value(java.lang.String),checked(java.lang.String, java.lang.String)): something was refused and the input could be read (withoutInput()). -
getForm
-
getMessage
The message above the form, ornull. -
get
The message next tofield, ornull. -
getAttachment
-
value
What the user submitted infield; empty when nothing is being refused. D-72b: each character XML cannot hold is given back as U+FFFD (displayable(java.lang.String)). R4-03: on a multipart body the text is read as typed (RepeatedField.text(org.kohsuke.stapler.StaplerRequest2, java.lang.String): thejsonblob's value, else the part as UTF-8), not as Stapler's ISO-8859-1 reading of the part. -
displayable
D-72b:textwith each character XML 1.0 cannot hold (U+0000, a lone surrogate, ...) replaced by U+FFFD, as a browser shows it. A refusal for such a character gives the input back this way, so the page never carries the character itself and the user sees where it was. -
checked
Whethervaluewas among the submitted values of the repeatedfield. D-37: on a multipart body Stapler keeps only the last part of the field, so the form'sjsonblob is read instead when it holds values for the field (RepeatedField), and a refused form re-renders the same boxes checked that the service saw. -
render
public void render(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object it) throws IOException, jakarta.servlet.ServletException Forwards the current request toit'sindex.jellywith HTTP 400 and this refusal attached.- Throws:
IOExceptionjakarta.servlet.ServletException
-
render
public void render(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object it, String view) throws IOException, jakarta.servlet.ServletException Asrender(StaplerRequest2, StaplerResponse2, Object), to the viewviewofit: D-66, a form submitted from a dialog is answered with the dialog's own view, so core's dialog replaces its form with the refused one (messages shown, input kept).- Throws:
IOExceptionjakarta.servlet.ServletException
-
render
public void render(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object it, String view, int status) throws IOException, jakarta.servlet.ServletException Asrender(StaplerRequest2, StaplerResponse2, Object, String)with the HTTP statusstatus(D-72: 413 for a body over the size cap).- Throws:
IOExceptionjakarta.servlet.ServletException
-
current
The refusal of formformon this request, or an empty one. Nevernull. -
current
The refusal attached to this request, whatever form it is for, or an empty one.
-