The Spring Framework

org.springframework.web.servlet.tags.form
Class SelectedValueComparator

java.lang.Object
  extended by org.springframework.web.servlet.tags.form.SelectedValueComparator

abstract class SelectedValueComparator
extends Object

Utility class for testing whether a candidate value matches a data bound value. Eagerly attempts to prove a comparison through a number of avenues to deal with issues such as instance inequality, logical (String-representation-based) equality and PropertyEditor-based comparison.

Full support is provided for comparing arrays, Collections and Maps.

Equality Contract

For single-valued objects equality is first tested using standard Java equality. As such, user code should endeavour to implement Object.equals(java.lang.Object) to speed up the comparison process. If Object.equals(java.lang.Object) returns false then an attempt is made at an exhaustive comparison with the aim being to prove equality rather than disprove it.

Special support is given for instances of LabeledEnum with a String-based comparison of the candidate value against the code of the LabeledEnum. This can be useful when a LabeledEnum is used to define a list of '<option>' elements in HTML.

Next, an attempt is made to compare the String representations of both the candidate and bound values. This may result in true in a number of cases due to the fact both values will be represented as Strings when shown to the user.

Next, if the candidate value is a String, an attempt is made to compare the bound value to result of applying the corresponding PropertyEditor to the candidate. This comparison may be executed twice, once against the direct String instances, and then against the String representations if the first comparison results in false.

Since:
2.0
Author:
Rob Harrop

Constructor Summary
SelectedValueComparator()
           
 
Method Summary
static boolean isSelected(BindStatus bindStatus, Object candidateValue)
          Returns true if the supplied candidate value is equal to the value bound to the supplied BindStatus.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectedValueComparator

SelectedValueComparator()
Method Detail

isSelected

public static boolean isSelected(BindStatus bindStatus,
                                 Object candidateValue)
Returns true if the supplied candidate value is equal to the value bound to the supplied BindStatus. Equality in this case differs from standard Java equality and is described in more detail here.


The Spring Framework

Copyright © 2002-2006 The Spring Framework.