BlazeDS, Flex, and Java - Can I treat a RemoteObject like an instance of the Java class?
I'm sorry if this question is a bit obvious, but I'm new to BlazeDS and can't seem to find an answer. I'm running Java on a BlazeDS server 开发者_如何学运维with a Flex front-end. I'd like to be able to instantiate my Java class only once, then have the Flex use the setters and getters to play with the data in the Java class (in a sense, treating the RemoteObject as if it were an instance of the class). As far as I've read this seems to be the way BlazeDS works, but every time I call any Java method from Flex, it calls Java constructors again, resetting anything input by the setter methods. Is there a way to have the server hold the instance of the Java class between method calls? Thanks!
You seem to have a misunderstanding of how this is works.
Objects in the Flex client and Objects on your server are completely independent. In normal circumstances, The Flash Player/A Flex App only talks to the remote service using either a WebSerice, HTTPService, or RemoteObject. RemoteObject supports AMF and Flash Remoting with BlazeDS, LiveCycle Data Services, ColdFusion, and a ton of other server side software.
When you make remote calls to the server, that request is no different than a standard web page call. It exists in "isolation" and knows nothing about any other call. In traditional HTML development we use session cookies to keep track of server sessions in a 'stateless' client. The same can be true for Flex calls. If your server sets cookies on the client; then the Flash Player will include those cookies in each request; matching up the service call to a server side session.
Whether an object is created with each call depends on what your remote call does.
The benefit that AMF / RemoteObject offers is that it can easily translate server side objects (Java Classes) to client side objects (ActionSCript classes). This is primarily used for passing of data between the two different entities. Usually people make Value Objects/Data Transfer Objects for this; but the classes can have the same exact functionality. It is not like the same object exists in both Flex and Java.
Does that help?
精彩评论