public class DefaultFormValidatorResults extends Object implements FormValidatorResults
Default implementation of the FormValidatorResults
interface.
This class provides a fully functional implementation of the FormValidatorResults
interface. Instances are initialized with a map that
contains the names of the validated fields and their corresponding
ValidationResult
objects. They are immutable and thus can be shared
between multiple threads.
Constructor and Description |
---|
DefaultFormValidatorResults(Map<String,? extends ValidationResult> fieldData)
Creates a new instance of
DefaultFormValidatorResults and
initializes it with a map holding information about fields and their
validation status. |
Modifier and Type | Method and Description |
---|---|
static ValidationResult |
createValidationErrorResult(Form form,
String key,
Object... params)
Creates a
ValidationResult object with an error message for a
validation message. |
static ValidationMessage |
createValidationMessage(Form form,
String key,
Object... params)
Obtains a
ValidationMessage object for the specified key. |
boolean |
equals(Object obj)
Compares this object with another one.
|
Set<String> |
getErrorFieldNames()
Returns a set with the names of those fields that are invalid.
|
Set<String> |
getFieldNames()
Returns a set with all defined field names.
|
ValidationResult |
getResultsFor(String field)
Returns the validation results for the specified field or null if
this field does not exist.
|
int |
hashCode()
Determines a hash code for this object.
|
boolean |
isValid()
Checks whether form validation was successful.
|
static FormValidatorResults |
merge(FormValidatorResults res1,
FormValidatorResults res2)
Returns a
FormValidatorResults object with the combined
information of the specified FormValidatorResults objects. |
String |
toString()
Returns a string representation for this object.
|
static Map<String,ValidationResult> |
validResultMapForForm(Form form)
Creates a
java.util.Map with validation information for all
fields of the specified Form . |
static DefaultFormValidatorResults |
validResultsForForm(Form form)
Creates a valid
DefaultFormValidatorResults for the fields of the
specified Form . |
public DefaultFormValidatorResults(Map<String,? extends ValidationResult> fieldData)
DefaultFormValidatorResults
and
initializes it with a map holding information about fields and their
validation status.fieldData
- the map with the field data (must not be nullIllegalArgumentException
- if the map is null or contains
null valuespublic static Map<String,ValidationResult> validResultMapForForm(Form form)
java.util.Map
with validation information for all
fields of the specified Form
. Each field is assigned a valid
ValidationResult
object. This method can be used by custom
FormValidator
implementations to initialize a map with data about
all form fields. Then, during validation, fields that were detected to be
invalid can be updated in this map. Finally, a DefaultFormValidatorResults
object can be created based on this map.form
- the Form
(must not be null)IllegalArgumentException
- if the Form
is nullpublic static DefaultFormValidatorResults validResultsForForm(Form form)
DefaultFormValidatorResults
for the fields of the
specified Form
. The resulting object stores a valid
ValidationResult
object for all fields that belong to the form.form
- the Form
(must not be null)DefaultFormValidatorResults
object for this formIllegalArgumentException
- if the Form
is nullpublic static ValidationMessage createValidationMessage(Form form, String key, Object... params)
ValidationMessage
object for the specified key. The
message is obtained from the current
ValidationMessageHandler
(which can be retrieved from the form's
TransformerContext
).form
- the Form
(must not be null)key
- the key of the validation error messageparams
- additional parameters for the validation error messageValidationMessage
object for the specified error
messageIllegalArgumentException
- if the Form
is nullpublic static ValidationResult createValidationErrorResult(Form form, String key, Object... params)
ValidationResult
object with an error message for a
validation message. This is a convenience method that obtains the
validation error message from the current
ValidationMessageHandler
and creates the corresponding
ValidationResult
object. It can be used for instance by a
FormValidator
that determines an incorrect field.form
- the Form
(must not be null)key
- the key of the validation error messageparams
- additional parameters for the validation error messageValidationResult
object initialized with this error
messageIllegalArgumentException
- if the Form
is nullpublic static FormValidatorResults merge(FormValidatorResults res1, FormValidatorResults res2)
FormValidatorResults
object with the combined
information of the specified FormValidatorResults
objects. If one
of the passed in objects is null, the other one is returned.
Otherwise a new FormValidatorResults
instance is created and
populated with the ValidationResult
objects contained in both
parameter objects. If necessary, the ValidationResult
objects are
also merged, so that the resulting object actually contains a union of
all validation messages.res1
- the first FormValidatorResults
objectres2
- the second FormValidatorResults
objectpublic boolean isValid()
isValid
in interface FormValidatorResults
public Set<String> getFieldNames()
getFieldNames
in interface FormValidatorResults
public Set<String> getErrorFieldNames()
getErrorFieldNames
in interface FormValidatorResults
public ValidationResult getResultsFor(String field)
getResultsFor
in interface FormValidatorResults
field
- the name of the desired fieldpublic boolean equals(Object obj)
public int hashCode()
public String toString()
ValidationResult
objects have proper toString()
implementations, the string
generated by the map is exactly what is needed to see which field has
which validation status.Copyright © 2016 The JGUIraffe Team. All rights reserved.