2 Replies Latest reply on Oct 10, 2007 10:42 AM by

    Reusable custom form for editing VO values

      I have a problem that I simply can’t find a good solution for. Does anyone know how can I reuse a custom form control as an editor for one or more VOs and detect when user interaction changes the values and not programmatic actions? The use case and my attempted solution are described below.

      Use Case:

      * The user is given a list of VOs that they can choose from.
      * When they choose a VO, values for all associated fields are displayed in a custom form
      * If the user edits the value of one or more fields, a “dirty flag” is displayed to indicate that data has been modified
      * The user is prompted to save or discard changes before they are allowed to select another VO or leave the form

      Attempted Solution:

      The solution I implemented basically binds the values of the VO directly to the associated data fields. So far so good. But how do we know when the data has changed? I then set up another one way binding from the UIComponents to a VO that is wrapped in a ObjectProxy. I attached a property change listener to the ObjectProxy. Every time values in the UI widgets changed to a different value, a property change event is fired. Therefore, whenever the user changes a value in the form, my listener hears about it and can set the dirty flag. Great so far, but here is the problem.

      Problem:

      Each time I select a new VO, some or all of the UI values change based upon the values stored in the selected VO. These changes cause propertyChange events for fire as expected. The basic problem is how do I know when the expected property change events have completed, and when property change events from user interaction begin? What I have observed is that events are received at different rates depending upon the UI widget (e.g. TextInput vs ComboBox). Events are received even after the new VO is set which suggests to me that they are dispatched in one or more other threads. Unlike my native Java language, I have no threading constructs to synchronize on in ActionScript 3.0.

      I hope I have explained the problem well enough. The bottom line is, how can I reuse a custom form as an editor for multiple VOs and detect when user interaction changes the values and not the programmatic action of setting the values of a new VO? Any advice would be appreciated. Thanks!!

      Jim
        • 1. Re: Reusable custom form for editing VO values
          AaffordableWeb
          For the TextInput elements, you can use the "textInput" event. This only fires when the user types data in the text input.

          For the ComboBox elements, you can use the "itemClick" event. This only fires when the user selects an item ind the ComboBox.

          Each Form element has events that only fire with user interaction. You will need to identify those, and use that event instead of the "change" event, which fires anytime there is a change user or otherwise.
          1 person found this helpful
          • 2. Re: Reusable custom form for editing VO values
            Ah...thank you for reminding me of these events! I will code listeners for each control as you suggested and see what happens. It certainly sounds like it will work. Thanks for your suggestion!!