I created a Java server which I used to run as an RMI service that talked to ColdFusion and then delivered data from ColdFusion to Flash in XML. We moved to Flex in Flash Builder 4 and decided to drop CF and make a web-service. In reading about Flex, it seemed great. I can return a List<Map> from Java (via a web-service) and then the List will be an ArrayList in Flex where the Maps will be Objects and on each Object I can get the value by using the Java key. For instance:
Now, in Flex, I should be able to do this:
I can do the above and have success. What is strange to me is the return (when I don't get an Apache error telling me that it can't create a mapping for ArrayList and I actually get a return anyway). To continue, now that my service is bound and I've gotten data back to my result handler, I should be able to do the following according to everything I read about ActionScript and Flex:
Are there any pointers you can give and/or would your book help me fix this? In order to get Maps or Lists that are usable by my ActionScript/Flex code, I have to do a lot of looping and printing to screen which is killing me in development and is not creating optimized code. What good does it do me to return an Object if I have to do exponentially more times the amount of processing than I would have to do if we just stayed with XML and JSON? Surely I am doing something wrong...
BTW, My sample code for getting returned values is not entirely correct. It needs one more inner loop to loop the number of keys and values stored in the object. In real life, the only way I've been able to make it work is to loop the ArrayCollection (which is really an ArrayList), get each object and then loop the object "for (var key:String in Object)" as an inner loop. Then for each "key" in "Object" get the "key" and then get the "value" such that the final result is var returnedValue = String (ArrayCollection.getItemAt(location).k["value"]. I need loops of loops to get collection values back which defeats the purpose of sending back maps at all. If one of my values of the map happens to be a Map, I wind up with loops building on top of loops just to get to the point of having usable Flex data.
Also, the first result handler you see in my post (the second code block) was put together when I was surprised by the first web-service call we tried. That call does not return a List. It returns a Map. I tried var:myValue = returned_map.server_key and got null pointers. I put in the loop to find out that my keys were all stored under "key" keys and my values were all stored under "value" keys. I was able to get the actual values I need through the loop. But, I should be able to get the values I need without any looping at all.
I tend to avoid using the Java Collections classes when doing SOAP web services as they're not really recommended per the w3c recommendations. To see the real benefits of using objects, you may want to look into using BlazeDS rather than SOAP.
Thanks Jeremy. We are trying to build something that works with every front end, not just Flex and thus built a standard web-service. It looks like the simplest means to getting this done is to go ahead and put Blaze DS in as yet another framework.
I read the first chapter. I thought it did a great job of explaining the concept, giving step by step examples with comprehensive information - without being verbose. It would have been a great resource to have a few weeks ago when I started learning Flex. The sample chapter is way better than any resource I was using to learning as it is so Java focused. Explaining Maven and Spring (both of which we use on this project) was fantastic.
Exposing your services using BlazeDS and SOAP are no longer mutually exclusive. There's no reason you can use those same services for both, these days it's just a matter of adding another annotation to your service methods. That way you can expose them as SOAP web services for the clients that want to use SOAP, and BlazeDS services for your Flex clients.
Makes sense. I am not the web-services guy. Have never done anything but call them. I wrote the code that goes on either side (the UI and the Server). As we got into using Flex, we had these discussions and tried to pick what we though would be most re-usable. Now that I've gotten BlazeDS up and experienced how it works, I can totally see how you can accomplish both tasks at the same time with one object.
As an aside for anyone who may stumble upon this and have the same trouble I did... When setting up BlazeDS using Maven instead of setting up per the instructions on Adobe, I had to add the apache-commons-http and logging dependency to the pom to get MessageBrokerServlet to instantiate.
BTW, now that we've gotten into Flex and are quickly adopting it, I am still a little lost as to why we went this way. I like the familiarity of ActionScript and the ease of MXML, but if you don't mind me getting off topic, what is the advantage of Flash over Java FX and/or Swing and Applets or even Swing and JNLP?
Maybe I should make this a new thread. Apart from your thoughts on the advantages of Flash over other solutions, does your book discuss where Flex is going and do you believe that html 5 or any other technology is likely to change the relevance of Flash?