0 Replies Latest reply on Oct 22, 2009 2:17 AM by dfghi

    Bidirectional binding and passing data.

    dfghi

      I started learning Flex and I have couple of problem of which I can't see a clear solution.

      Flex 4 has two way binding, but how can I use it with data type different from strings? I receive from a web service dates and numbers, let the user edit them and send them back to the web service. Flex 4 code generator created all the necessary objects, that contain numers and dates types. Presenting them to the user in text fields (or date fields) is easy, but I can't get such a simple way to send them back. When I try two way binding it gives compilation error because it think I'm trying to force a cast from String to Number or Date. If I understand correctly, the only way to get the data back to the web service is:

      • Introduce validators for Numbers and Dates
      • For each of the form element, check if it is valid
      • If all of them are valid, convert them manually to the appropriate type
      • Populate back the original object with new values (and then send it to the web service)

      Is there a smarter way to let the two way binding work the way is meant to be? Is there some way to set the converter to use when binding back from String to Number?

      By the way, is there some simple way to ask a Form object that all the contained fields are valid?

       

      The second problem regards passing data among different views: is there a standard way in Flex to "share" data between different mxml files? I have two scenarios:

      • A view (mxml file) uses a lot of components (other mxml files, that may include other components as well). There are a few objects, mostly data container, that I'd like to use in most of this hierarchy. Which is the best way to share these objects? Do I have to set something static in the root view and have all the other components access them statically? Or do I have to write setters in all the components in the hierarchy and pass all the objects down the hierarchy? Is there a quick way to set up a sort of "session" for this hierarchy and access it?
      • A view (mxml file) presents a list of results. Selecting/clicking on one of the results the user goes to another view (mxml file, may be a module), but in the new view I need a reference to the data the user selected in the previous view. The first solution here seems to be using an event and passing the data with it, but is there any other way? I'm looking for something that can cover both this and the previous case.

       

      Any suggestion is welcome. Sorry if the question was already posted but I didn't find any clear answer.