Java and flex integration question

I have a flexible web application and want to integrate with Java.

The application will have a very small database (2-3 tables) and some routine logic like sending mail.

According to this link ( http://learn.adobe.com/wiki/display/Flex/2b.+Code+Files ) I also need a .jsp file. I thought Flex would only be interested in my classes?

Also, my java method will take parameters - how to pass values ​​in flex.mxml page text files to java method? A simple example will really help me.

When using httpservice calls, is there anything else I need to know?

thank

+1


source to share


3 answers


Check out Blaze DS. It's pretty easy to set up so you can call methods on your Java classes from Flex.

http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/

Basically, you register a RemoteObject that references the Flash Remoting endpoint URL and specifies the destination (usually the class name). Consult the WebOrb docs on how to do this. After that, you can simply call RemoteObject like this:



var token: AsyncToken = emailService.sendEmail (subject, body); token.addResponder (responderImpl);

You create an implementation of the IResponder interface and register it against the "AsyncToken" that is returned from remote calls to Flex. All calls to the server in Flex are asynchronous, so you register a responder, which then has a result or error method called.

+3


source


Another option is to use Ajax (like JavaScript) as an intermediary between Flex and your server-side Java-Java to ensure a good separation of the presentation and business layers. I've seen this with success - Flex can call JavaScript easily, and there are many tried and tested patterns to expose your Java objects / methods to JavaScript to invoke Ajax style ( DWR is a good choice).



+1


source


If you are using BlazeDS (which is a servlet that you remove on your web server), you will be able to pass ActionScript objects to your remote calls. They will be cabled to AMF and then merged with Java objects. You need to use a code generator to use your Java remote service and create the appropriate ActionScript classes for use on the client (to send arguments and get the result).

Flex also supports ala SOAP style web service calls. Less efficient than AMF, but not a big deal if there is no data exchange.

When I'm in a rush to do something real quick and dirty, I just make an HttpService send () call where I wrote an HTTP POST (no data shows up in the url as in GET). A fast-written Java servlet handles POST and receives the data as a map of name / value pairs in text format. (The HttpSerivce.send () method behaves asynchronously like the AJAX XmlHttpRequest () mechanism.)

It just doesn't get any easier than doing something like this, but name / value pairs are not as flexible as structured data. Sometimes you have to deal with more complex structured data. Consequently, serializing ActionScript model objects for plots of AMF objects using BlazeDS remote access comes into its own.

+1


source







All Articles