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:
- Right-click the validator class in the Projects window and choose Compile File.
- Drag the validator from the Projects window to the Design view of your form.
The validator is added to your form as a bean.
- Right-click the target of your binding and choose Bind > TargetProperty.
- In the Bind Dialog box, select the Advanced tab.
- From the Validator drop-down list, choose the validator you have added to the form.
- Click OK.
- You can also add the validation code directly by clicking
the ellipsis (...) button, and selecting Custom Code from the Select Validator
Property Using drop-down list.
-
See Also
- Converting Values Between Source and Target Properties
- About Beans Binding in Java Desktop Applications
- Binding Data to a Swing Component
Legal Notices