I have the following lines in my code. I am validating captcha in a JSP form.
I don’t understand the meaning of all arguments passed in the FieldError object.
if (!reCaptchaResponse.isValid()) {
FieldError fieldError = new FieldError("CaptchaObj", "captcha",
uresponse, false, new String[] { "badCptcha.CaptchaObj.captcha" },
null, "Please, Try Again ");
result.addError(fieldError);
}
HERE result variable is of type BindingResult.
I want the exact meaning of each argument in the constructor of the FieldError object and especially for the code argument in the constructor which of type String.
I would suggest reading the API documentation for field error found here.
It mentions the following parameters for this constructor:
One of the most important parameters is the codes parameter, which contains a code that will be searched for within your message sources. If found the message matching this code will be displayed. Message sources can take arguments, so a Message Source can contain an entry like:
In this case the code would be
typeMismatch.startDateand the message corresponding with this code will display the first argument followed by the message. The{0}piece of the message indicates that it should display the first argument. These arguments are provided by the 6th parameter in the constructor, which in your example is null.