PDA

View Full Version : Flex - ActionScript 3 - Java Backend


PieterBosman
04-29-2008, 08:10 AM
Hey Guys,

I'm a Java Coder. Don't shoot me ;)
In the last couple of weeks I've been amazed at the power of Flex based RIA's so I felt the need to test stuff out.

I'm using Eclipse Europa + Flex Plugin and a Tomcat Server on which normally LifeCycle DS & BlazeDS (in so far these are different...) are present.

Anyway, I've been trying to use AMF to communicate with a Java Backend program from within a Flex RIA. And I must say I find it rather easy. So far, all is well!

However...

I'm at the point where I need to interpret my Java beans (pojo's if you will) at client side. There is however one small catch: my Java Backend is created in a seperate Flex Project in my Eclipse.
This implies, I think, that the [RemoteClass(alias="...")] system might not be as straightforward as I found on different websites.
Furthermore, my Eclipse Content Assistent doesn't recognize the "RemoteClass' metatag, hence no coding help there :confused:

I have been able to directly call the public variables in my java backing bean, but as other java coders out there might understand, the concept of publicly declaring variables makes me shiver...
So I just want to map my server side bean (with private variables & public getters/setters) to a client side AS bean (with private variables & public getters/setters) and if possible in such a matter I can use an action to 'refresh' the bean on client side :)

So basically I got one 'simple' question... How do I interpret my Java backing bean in my Flex RIA, keep in mind above stated situation please!

Flash Gordon
04-29-2008, 08:16 AM
Um.....I don't think flash can "interpret" your Java. I don't have much experience in this area, but I would suggest looking into socket connections. The way Flash typically interacs with other applications is by passing data around (xml for example) and not having access to private or public variables of another language.

PieterBosman
04-29-2008, 08:35 AM
Hey Flash,

thanks for your input, but I'm testing stuff based upon sites like this one: http://sujitreddyg.wordpress.com/2008/01/16/mapping-action-script-objects-to-java-objects/

The thing is, they're mapping java objects in AS objects, but I can't seem to do it in the way he's describing :)
One thing among others is that the "RemoteClass" Metatag is not supported or recognized in my Eclipse...
Although I'm using the Flex 3 plugin on Eclipse Europa...

Flash Gordon
04-29-2008, 09:05 AM
I dunno about all of that stuff. I just know that access private variables/methods of Java from Actionscript is probably not as it sounds (and incredibly bad OOP). I haven't touched Flex for a day in my lfe, and I'm quite new to Java, so I dunno. However, I've never seen Flash communicate with another language without going through a public API.

You're probably get some better responses in the morning when people wake up. It's VERY late here.

PieterBosman
04-30-2008, 06:54 AM
Nobody around with any experience in this?
I can't imagine there hasn't been anyone who has had the same experience as I did...

bowljoman
05-03-2008, 06:57 PM
Java reflection will look into all private members of the class.

No tricks here really. No matter what you create on the server, you need action script definitions also.

When Reflection gets the class information, you collect it and instance a actionscript class. Nothing special, and possibly overkill for passing simple data and objects that manage simple data.

PieterBosman
05-05-2008, 07:04 AM
Java reflection will look into all private members of the class.

No tricks here really. No matter what you create on the server, you need action script definitions also.

When Reflection gets the class information, you collect it and instance a actionscript class. Nothing special, and possibly overkill for passing simple data and objects that manage simple data.
Hey Bowljoman,

I'm terribly sorry, but I can't make heads nor tails from your post, must be me, I'm sure.

Java reflection -> Do you mean the 'introspection' class in java? The one that only looks at the 'public' variables?
Action script definitions -> Aye, I understand that, but how to I parse my 'result' I get from calling an AMF java method into an AS object or array of objects?

That's basically what I'm asking :)

Thanks for your reply in any case!

PieterBosman
05-06-2008, 09:50 AM
Nobody around who tried the same stuff as I'm trying?
Or could point me towards some comprehensive tutorial online somewhere?

bowljoman
05-12-2008, 01:17 AM
No, I did indeed mean the reflection API in the java.reflect package, which does parse private/protected members and methods.

The sample you linked to mentions it as well. So you have a java servlet that returns an object, and its passed across in an encoded format for whatever proxy you use.

I prefer xml objects over http instead of amf except in rtmp by which is amf itself.