Top Description Fields Constructors Methods
org.springframework.web.reactive.result.view

public Class BindStatus

extends Object
Class Inheritance
Imports
java.beans.PropertyEditor, java.util.Arrays, .List, org.springframework.beans.BeanWrapper, .PropertyAccessorFactory, org.springframework.context.NoSuchMessageException, org.springframework.lang.Nullable, org.springframework.util.ObjectUtils, .StringUtils, org.springframework.validation.BindingResult, .Errors, .ObjectError, org.springframework.web.util.HtmlUtils

Simple adapter to expose the bind status of a field or object. Set as a variable by FreeMarker macros and other tag libraries.

Obviously, object status representations (i.e. errors at the object level rather than the field level) do not have an expression and a value but only error codes and messages. For simplicity's sake and to be able to use the same tags and macros, the same status class is used for both scenarios.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
5.0
See Also
RequestContext#getBindStatus

Field Summary

Modifier and TypeField and Description
private Object
private BindingResult
private PropertyEditor
private final String[]
private String[]
private final Errors
private final String
private final boolean
private List<? extends ObjectError>
private final String
private final RequestContext
private Object
private Class<?>

Constructor Summary

AccessConstructor and Description
public
BindStatus(RequestContext
the current RequestContext
requestContext
,
String
the bean and property path for which values and errors will be resolved (e.g. "customer.address.street")
path
,
boolean
whether to HTML-escape error messages and string values
htmlEscape
)

Create a new BindStatus instance, representing a field or object status.

Method Summary

Modifier and TypeMethod and Description
public PropertyEditor

Returns:

the associated PropertyEditor, or null if none
findEditor
(Class<?>
the value class that an editor is needed for
valueClass
)

Find a PropertyEditor for the given value class, associated with the property that this bound status is currently bound to.

public Object
getActualValue()

Return the actual value of the field, i.e. the raw property value, or null if not available.

public String
getDisplayValue()

Return a suitable display value for the field, i.e. the stringified value if not null, and an empty string in case of a null value.

public PropertyEditor

Returns:

the current PropertyEditor, or null if none
getEditor
()

Return the PropertyEditor for the property that this bind status is currently bound to.

public String
getErrorCode()

Return the first error codes for the field or object, if any.

public String[]
getErrorCodes()

Return the error codes for the field or object, if any.

public String
getErrorMessage()

Return the first error message for the field or object, if any.

public String[]
getErrorMessages()

Return the resolved error messages for the field or object, if any.

public String

Returns:

the error message string
getErrorMessagesAsString
(String
separator string, e.g. ", " or "
"
delimiter
)

Return an error message string, concatenating all messages separated by the given delimiter.

public Errors

Returns:

the current Errors instance, or null if none
getErrors
()

Return the Errors instance (typically a BindingResult) that this bind status is currently associated with.

public String
getExpression()

Return a bind expression that can be used in HTML forms as input name for the respective field, or null if not field-specific.

public String
getPath()

Return the bean and property path for which values and errors will be resolved (e.g. "customer.address.street").

public Object
getValue()

Return the current value of the field, i.e. either the property value or a rejected update, or null if not field-specific.

public Class<?>
getValueType()

Get the 'Class' type of the field.

private static String[]
initErrorCodes(List<? extends ObjectError> objectErrors)

Extract the error codes from the ObjectError list.

private String[]
initErrorMessages()

Extract the error messages from the ObjectError list.

public boolean
isError()

Return if this status represents a field or object error.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

actualValueback to summary
private Object actualValue
Annotations
@Nullable
bindingResultback to summary
private BindingResult bindingResult
Annotations
@Nullable
editorback to summary
private PropertyEditor editor
Annotations
@Nullable
errorCodesback to summary
private final String[] errorCodes
errorMessagesback to summary
private String[] errorMessages
Annotations
@Nullable
errorsback to summary
private final Errors errors
Annotations
@Nullable
expressionback to summary
private final String expression
Annotations
@Nullable
htmlEscapeback to summary
private final boolean htmlEscape
objectErrorsback to summary
private List<? extends ObjectError> objectErrors
Annotations
@Nullable
pathback to summary
private final String path
requestContextback to summary
private final RequestContext requestContext
valueback to summary
private Object value
Annotations
@Nullable
valueTypeback to summary
private Class<?> valueType
Annotations
@Nullable

Constructor Detail

BindStatusback to summary
public BindStatus(RequestContext requestContext, String path, boolean htmlEscape) throws IllegalStateException

Create a new BindStatus instance, representing a field or object status.

Parameters
requestContext:RequestContext

the current RequestContext

path:String

the bean and property path for which values and errors will be resolved (e.g. "customer.address.street")

htmlEscape:boolean

whether to HTML-escape error messages and string values

Exceptions
IllegalStateException:
if no corresponding Errors object found

Method Detail

findEditorback to summary
public PropertyEditor findEditor(Class<?> valueClass)

Find a PropertyEditor for the given value class, associated with the property that this bound status is currently bound to.

Parameters
valueClass:Class<?>

the value class that an editor is needed for

Returns:PropertyEditor

the associated PropertyEditor, or null if none

Annotations
@Nullable
getActualValueback to summary
public Object getActualValue()

Return the actual value of the field, i.e. the raw property value, or null if not available.

Annotations
@Nullable
getDisplayValueback to summary
public String getDisplayValue()

Return a suitable display value for the field, i.e. the stringified value if not null, and an empty string in case of a null value.

This value will be an HTML-escaped String if the original value was non-null: the toString result of the original value will get HTML-escaped.

getEditorback to summary
public PropertyEditor getEditor()

Return the PropertyEditor for the property that this bind status is currently bound to.

Returns:PropertyEditor

the current PropertyEditor, or null if none

Annotations
@Nullable
getErrorCodeback to summary
public String getErrorCode()

Return the first error codes for the field or object, if any.

getErrorCodesback to summary
public String[] getErrorCodes()

Return the error codes for the field or object, if any. Returns an empty array instead of null if none.

getErrorMessageback to summary
public String getErrorMessage()

Return the first error message for the field or object, if any.

getErrorMessagesback to summary
public String[] getErrorMessages()

Return the resolved error messages for the field or object, if any. Returns an empty array instead of null if none.

getErrorMessagesAsStringback to summary
public String getErrorMessagesAsString(String delimiter)

Return an error message string, concatenating all messages separated by the given delimiter.

Parameters
delimiter:String

separator string, e.g. ", " or "
"

Returns:String

the error message string

getErrorsback to summary
public Errors getErrors()

Return the Errors instance (typically a BindingResult) that this bind status is currently associated with.

Returns:Errors

the current Errors instance, or null if none

Annotations
@Nullable
See Also
org.springframework.validation.BindingResult
getExpressionback to summary
public String getExpression()

Return a bind expression that can be used in HTML forms as input name for the respective field, or null if not field-specific.

Returns a bind path appropriate for resubmission, e.g. "address.street". Note that the complete bind path as required by the bind tag is "customer.address.street", if bound to a "customer" bean.

Annotations
@Nullable
getPathback to summary
public String getPath()

Return the bean and property path for which values and errors will be resolved (e.g. "customer.address.street").

getValueback to summary
public Object getValue()

Return the current value of the field, i.e. either the property value or a rejected update, or null if not field-specific.

This value will be an HTML-escaped String if the original value already was a String.

Annotations
@Nullable
getValueTypeback to summary
public Class<?> getValueType()

Get the 'Class' type of the field. Favor this instead of 'getValue().getClass()' since 'getValue()' may return 'null'.

Annotations
@Nullable
initErrorCodesback to summary
private static String[] initErrorCodes(List<? extends ObjectError> objectErrors)

Extract the error codes from the ObjectError list.

initErrorMessagesback to summary
private String[] initErrorMessages() throws NoSuchMessageException

Extract the error messages from the ObjectError list.

isErrorback to summary
public boolean isError()

Return if this status represents a field or object error.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override