TS 61 BeanBinding

Beans Binding Test Specification

Author: Jiri Vagner
Version: 6.1
Lastupdate: 2008/01/29
Introduction:

Contents


Test suite: Basic test

Purpose: Tests basic beans binding functionality.
Setup: Create new Java Application project, add new jFrame form and add two jLabel components into that form. Renamed labels to sourceLabel and targetLabel and change text value of labels to "source" and "target"

  1. Bind text property of JLabel components
    1. Invoke popup menu for targetLabel component node in Inspector window
    2. Click "Bind -> text" menu item
    3. In Bind dialog in Binding source select sourceLabel component
    4. In Bind Expression tree combo list doubleclik on "text java.lang.String" node and press OK
    • EXPECTED RESULT: Now "text" property of two jlabels are binded. Binding works also in desing time, targetLabel now contains value from binded sourceLabel component.
  2. Check the generated code
    1. In form designer press Source button and expand initComponents() method body
    • EXPECTED RESULT: Binding dialog added there binding code, check the lines which starts with "binding...". There should be initialization of binding context object, binding of our two labels and start of binding process.


Test suite: Advanced test

Setup: Use the form with two binded jlabels from the previous test case.

  1. Creating special buttons
    1. Add two jbutton components into form, change their names to sourceButton and targetButton and change their text to "Change source" and "Change target"
    2. Invoke popup menu for sourceButton and click item "Events -> Action -> actionPerformed"
    3. Into generated event handler paste:
       sourceLabel.setText(sourceLabel.getText() + "+");
    4. Do the steps 2 and 3 for button targetButton
    • EXPECTED RESULT: On the form there are two buttons for changing target and source property values.
  2. Update modes - Always sync
    1. Execute form (SHIFT + F6) and press sourceButton and targetButton
    • EXPECTED RESULT: Beans binding propagates changes of source text property value to target value and changes of target value to source value. This "Always sync (read/write)" update mode is default. Check the Advancec tab in Bind dialog.
  3. Update modes - Only read from source
    1. Invoke popup menu for targetLabel component node in Inspector window
    2. Click "Bind -> text" menu item
    3. In Bind dialog select Advanced tab
    4. In Update mode listbox select "Only read from source (read-only)" item and press OK
    5. Execute form (SHIFT + F6) and press sourceButton and targetButton
    • EXPECTED RESULT: Binding library will propagate only changes of source text property value. Changes of target text property are not propagated.
  4. Update modes - Read from source once
    1. Invoke popup menu for targetLabel component node in Inspector window
    2. Click "Bind -> text" menu item
    3. In Bind dialog select Advanced tab
    4. In Update mode listbox select "Read from source once (read once)" item and press OK
    5. Execute form (SHIFT + F6) and press sourceButton and targetButton
    • EXPECTED RESULT: Binding library will propagate changes of source text property value only after frame start.
  5. Alternate Values - Null value
    • Comments: If the binding source is null, you can set your own value for target property.
    1. Add new jLabel component and rename it to "nullLabel"
    2. Invoke bind dialog for text property of nullLabel
    3. In Bind dialog in Binding source select Form
    4. In Bind Expression select iconImage property (this property is null in this new test form)
    5. Go to Advanced tab and check "Null Source Value" checkbox
    6. Click "..." button for Null Source Value property and in popup dialog type text "item is null" and press OK
    7. Press OK button and check the form
    • EXPECTED RESULT: Binding will change the text property of nullLabel to "item is null". It will use null value alternate, because binding source is null.
  6. Alternate Values - Incomplete path value
    • Comments: If the binding source path is incomplete, you can set your own value for target property. For example if you will bind your component value to some custom User object to its property user.address.zipcode and user object will containt empty or null address component.
    1. Add new jLabel component and rename it to "incompletePathLabel"
    2. Invoke bind dialog for text property of incompletePathLabel
    3. In Bind dialog in Binding source select Form
    4. In Bind Expression select iconImage->accelerationPriority property (iconImage property is null, path is incomplete)
    5. Go to Advanced tab and check "Unreadable Source Value" checkbox
    6. Click "..." button for Unreadable Source Value property and in popup dialog type text "path is incomplete" and press OK
    • EXPECTED RESULT: Binding will change the text property of incompletePathLabel to "path is incomplete". It will use alternate value, because binding source expression path is evaluated as incomplete path.
  7. Convertors
    • Setup: Create empty form, add two JLabel components and rename them to "sourceLabel" and "targetLabel"
    1. Copy file TestConverter.java file into your project and change package name. Compile it!!!
    2. Drag the TestConverter file from Project tree into JFrame Form.
    3. Set the alignmentX property of sourceLabel component to 0.3 (or choose some other number between 0.1 and 0.9)
    4. Invoke popup menu for targetLabel component node in Inspector window
    5. Click "Bind -> text" menu item
    6. In Bind dialog in Binding source select sourceLabel component
    7. In Bind Expression tree combo list doubleclik on "alignmentX float" node
    8. Go to Advanced tab and click the "..." button for Converter property
    9. Go to Advanced tab and in Converter section select testConverter1 component
    10. Close Bind dialog using OK button and run form (SHIFT + F6)
    • EXPECTED RESULT: In runtime, the targetLabel text is "3.0" (it means alignmentX of sourceLabel * 10). Change alignmentX property of sourceLabel and run JFrame form again.
  8. Validators
    • Setup: Create empty form, add two JLabel components and rename them to "sourceLabel" and "targetLabel"
    1. Copy file TestValidator.java file into your project and change package name.
    2. Build validator file and drag it from Project tree and drop it into form
    3. Add JButton component, rename it to "changeTarget" and set text "Change target"
    4. Invoke popup menu for "changeTarget" JButton and click item "Events -> Action -> actionPerformed"
    5. Into generated event handler paste: targetLabel.setText(targetLabel.getText() + "+");
    6. Invoke popup menu for targetLabel component node in Inspector window
    7. Click "Bind -> text" menu item
    8. In Bind dialog in Binding source select sourceLabel component
    9. In Bind Expression tree combo list doubleclik on "text java.lang.String" node
    10. Go to Advanced tab and in Validator section select testValidator1 component
    11. Close Bind dialog using OK button and run form (SHIFT + F6)
    12. Click button several times to increase label length
    • EXPECTED RESULT: After few clicks login validator will stop writing "Too short" msgs into console output and starts writing "OK". For more details check the content of a method TestValidator.validate(). In real app programmer should implement BindingListener and use it instead of ugly console println(). :)
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo