Validating Target Value Changes in Bindings (Java Desktop Applications)

See Also

When you bind the values of two properties of two objects, you sometimes need to validate any changes to the target property before they are written back to the source (such as a database). To validate a target, you specify a validator that extends org.jdesktop.beansbinding.Validator.

To write a custom validator, create a class that extends org.jdesktop.beansbinding.Validator. Your class needs to implement the validate(T value) method. For a valid value, validate(T value) returns null. For an invalid value, it returns a Result object describing the problem for the invalid value.

To use a custom validator in a binding:

  1. Right-click the validator class in the Projects window and choose Compile File.
  2. Drag the validator from the Projects window to the Design view of your form.

    The validator is added to your form as a bean.

  3. Right-click the target of your binding and choose Bind > TargetProperty.
  4. In the Bind Dialog box, select the Advanced tab.
  5. From the Validator drop-down list, choose the validator you have added to the form.
  6. Click OK.
See Also
Converting Values Between Source and Target Properties
About Beans Binding in Java Desktop Applications
Binding Data to a Swing Component

Legal Notices