tags:

views:

973

answers:

4

I have a flex web app and want to integrate it with Java.

The app 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 would need to also have a .jsp file. I thought Flex would only be interested in my classes?

Also, my java method would take parameters - how can I pass the values in the textboxes of a flex .mxml page to the java method? A simple example would really help me.

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

Thanks

+2  A: 

Check out Blaze DS. It's pretty simple to set this up so that you can invoke methods on your Java classes from Flex.

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

Basically you register a RemoteObject that references the URL of your Flash Remoting endpoint and specifies the destination (usually the class name). Consult the WebOrb docs on how to do that. Once that's done, you can just invoke the RemoteObject like so:

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

You create an implementation of the IResponder interface and register it against the "AsyncToken" which is returned from remoting calls in Flex. All calls to the server in Flex are asynchronous which is why you register a responder which then has either the result or fault method invoked.

cliff.meyers
+1  A: 

Another option would be to use Ajax (i.e. JavaScript) as an intermediary between Flex and your server side Java to help keep the view and business layers nicely decoupled. I have seen this done with success - Flex can invoke JavaScript easily, and there are many proven patterns to expose your Java objects/methods to JavaScript for Ajax style invocation (DWR is a good choice).

Pete
A: 

I have decided to use Weborb.

I have an email class, which has a method to send off the email. This takes parameters (string subject, string body). These will obviously be filled in at the Flex ui level inside the textboxes on the page.

My question is, when I press the submit button on my Flex app for the email submission, how can I invoke a java method and supply these textbox values as parameters?

I know how weborb and Flex work together so Flex can invoke a java method and display the result inside of Flash, but how does it work when I want to pass Flex data as a Java method?

Thanks

dotnetdev
Update your original question rather than replying in an answer. Please see Stackoverflow usage guidelines.
Pete
+1  A: 

If you use BlazeDS (which is a servlet that you drop in your web server), you'll be able to pass ActionScript objects on your remoting calls. Those will be marshalled to AMF over the wire, and then ummarshalled to Java objects. You need to use a code generator tool to take your Java remoting service and create corresponding ActionScript classes to use on the client (for sending up the arguments and then receiving the result).

Flex also supports web service calls ala SOAP style. Less efficient than AMF but no biggie if there's not much data being exchanged.

When I'm in a hurry to do something real quick and dirty, I just do a HttpService send() call where I've composed an HTTP POST (the data is not visible in the URL as it is with a GET). A quickly written Java servlet processes the 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 simpler than doing something like that, but name/value pairs is not as flexible as structured data. Sometimes you need to deal with more complex structured data. Hence serializing ActionScript model objects to AMF object graphs via BlazeDS remoting comes into its own.

RogerV