Re: [flexcoders] Re: Issue when converting HashMap(Java) into Object (ActionScript)

2008-09-08 Thread Josh McDonald
Then the problem is with your definition of C, and it's being unmarshalled
incorrectly. That's basically what I was trying to say, but I think I
explained it poorly.

When you make no explicit reference to the class C it is never included in
your SWF, so the remoting system never sees the [RemoteObject] annotation,
and hence the unmarshaller simply creates an Object (instead of a C). When
you're referencing B with the expression "(is B)" the compiler includes B in
your swf, and then it encounters a reference to C inside B, so it includes
that as well. When you fetch your object, the unmarshaller sees that "myC"
should be a C, so it instantiates a new C and then tries to populate it.
Somehow the strongly-typed population of C is failing, so you get the
default values. But when you never reference B, the compiler never sees C,
so the unmarshaller never knows about it and just creates an Object (or more
likely an ObjectProxy) for the "myC" field. Also note that in this case your
objects you expect to be instances of B will also actually be ObjectProxy
instances. Do a little single-step debugging and some
trace(getQualifiedClassName(someInstance)) to see what's really going on
inside your SWF at runtime to see if what I'm saying is what's actually
happening.

But it looks to me if you're only interested in fixing the problem (not
everybody wants to know as much detail as I do I've learned over the years),
go over your Flex and Java definitions of C with a fine-tooth comb and make
sure they match!

-Josh

On Tue, Sep 9, 2008 at 10:16 AM, dmiramontesval <[EMAIL PROTECTED]
> wrote:

> I don't think that is what's happening, when i use "if (i is B)" the
> condition does work, it enters the if block but it resets the C object.
>
> I tried a new thing, on B i changed the myC declaration
>
> public var myC:Object; // Object instead of C
>
> By doing this i can use if (i is B) and now it doesn't reset the
> values of myC, but the problem is that if i try the following:
>
> if (i.myC is C)
>
> this gives me false :(
>
>
> Any ideas?
>
>
> --- In flexcoders@yahoogroups.com, "Josh McDonald" <[EMAIL PROTECTED]> wrote:
> >
> > Sounds to me like you're accidentally declaring b.myC as a static,
> perhaps.
> >
> > Actually, double check your examples (perhaps using the link report
> option
> > on MXMLC). It might be that you're not actually referencing B and
> it's not
> > becoming part of your SWF, in which case you're getting a "best guess"
> > object where you think you're getting an instance of B (you can't
> check for
> > "is B" without including it in your swf, but you can check for "!(is A)"
> > without including the B class.
> >
> > In which case, it's the unmarshaller that's killing your data when
> trying to
> > convert it to a B (becuase now it knows to do it, once you've
> referenced the
> > class and it's in your SWF). Double check how you're defining C in
> your Flex
> > *and in your Java*.
> >
> > Also, if it's the unmarshaller that's the problem, I'd definitely try a
> > compile against Flex 3.01 and see if the problem goes away. If
> you've got a
> > smallest-failiing case project for this bug it should only take you
> a few
> > minutes.
> >
> > -Josh
> >
> > On Tue, Sep 9, 2008 at 9:53 AM, dmiramontesval
> > <[EMAIL PROTECTED]>wrote:
> >
> > > Um actually my example is wrong, i was missing something, let me
> > > explain again:
> > >
> > > I have 3 classes as a matter of fact, classes A and B are correct but
> > > i forgot to mention that inside B there is an object C:
> > >
> > > [RemoteClass(alias="com.test.B")]
> > > public class B {
> > > public var id:Number;
> > > public var name:String;
> > > public var myC:C
> > > }
> > >
> > > [RemoteClass(alias="com.test.C")]
> > > public class C {
> > > public var testVar1:Number;
> > > public var testVar2:String;
> > > }
> > >
> > >
> > > A objectA = new A();
> > > objectA.myMap = new HashMap();
> > > B objectB1 = new B();
> > > C objectC1 = new C();
> > > objectB1.id = 1;
> > > objectB1.name = "Test";
> > > objectC1.testVar1 = 2;
> > > objectC1.testVar2 = "Hello";
> > > objectB1.myC = objectC1;
> > > myMap.put("key1", objectB1);
> > >
> > >
> > > Now here is the deal, the only property being reset is the C object,
> > > the id and name properties are not reset
> > >
> > >
> > > for each(var i:* in objectA.myMap) {
> > >   if (i is B) {
> > > trace(i.id + " " + i.name);
> > >  trace(i.myC.testVar1 + " " + i.myC.testVar2);
> > >   }
> > > }
> > >
> > > The first trace works fine, but the second trace shows NaN and empty
> > > string.
> > > If i change the code to:
> > >
> > > for each(var i:* in objectA.myMap) {
> > >   if (!(i is A)) {
> > > trace(i.id + " " + i.name);
> > >  trace(i.myC.testVar1 + " " + i.myC.testVar2);
> > >   }
> > > }
> > >
> > > Both traces work fine, prints 1 Test and 2 Hello.
> > >
> > > Like you said i have some logic inside the B constructor:
> > >
> > > public function B() {
> > >   myC = new C();
> > > }
> > >
> > >

Re: [flexcoders] Re: Issue when converting HashMap(Java) into Object (ActionScript)

2008-09-08 Thread Josh McDonald
Sounds to me like you're accidentally declaring b.myC as a static, perhaps.

Actually, double check your examples (perhaps using the link report option
on MXMLC). It might be that you're not actually referencing B and it's not
becoming part of your SWF, in which case you're getting a "best guess"
object where you think you're getting an instance of B (you can't check for
"is B" without including it in your swf, but you can check for "!(is A)"
without including the B class.

In which case, it's the unmarshaller that's killing your data when trying to
convert it to a B (becuase now it knows to do it, once you've referenced the
class and it's in your SWF). Double check how you're defining C in your Flex
*and in your Java*.

Also, if it's the unmarshaller that's the problem, I'd definitely try a
compile against Flex 3.01 and see if the problem goes away. If you've got a
smallest-failiing case project for this bug it should only take you a few
minutes.

-Josh

On Tue, Sep 9, 2008 at 9:53 AM, dmiramontesval
<[EMAIL PROTECTED]>wrote:

> Um actually my example is wrong, i was missing something, let me
> explain again:
>
> I have 3 classes as a matter of fact, classes A and B are correct but
> i forgot to mention that inside B there is an object C:
>
> [RemoteClass(alias="com.test.B")]
> public class B {
> public var id:Number;
> public var name:String;
> public var myC:C
> }
>
> [RemoteClass(alias="com.test.C")]
> public class C {
> public var testVar1:Number;
> public var testVar2:String;
> }
>
>
> A objectA = new A();
> objectA.myMap = new HashMap();
> B objectB1 = new B();
> C objectC1 = new C();
> objectB1.id = 1;
> objectB1.name = "Test";
> objectC1.testVar1 = 2;
> objectC1.testVar2 = "Hello";
> objectB1.myC = objectC1;
> myMap.put("key1", objectB1);
>
>
> Now here is the deal, the only property being reset is the C object,
> the id and name properties are not reset
>
>
> for each(var i:* in objectA.myMap) {
>   if (i is B) {
> trace(i.id + " " + i.name);
>  trace(i.myC.testVar1 + " " + i.myC.testVar2);
>   }
> }
>
> The first trace works fine, but the second trace shows NaN and empty
> string.
> If i change the code to:
>
> for each(var i:* in objectA.myMap) {
>   if (!(i is A)) {
> trace(i.id + " " + i.name);
>  trace(i.myC.testVar1 + " " + i.myC.testVar2);
>   }
> }
>
> Both traces work fine, prints 1 Test and 2 Hello.
>
> Like you said i have some logic inside the B constructor:
>
> public function B() {
>   myC = new C();
> }
>
> I commented the constructor and instead of getting the values reset i
> got an error saying i tried to access a null reference, since C is
> null (if i don't use an instance of B then it works fine).
>
> So i am kinda back where i started, when i use the B class the C
> object inside each B object is reset.
>
>
> --- In flexcoders@yahoogroups.com, "Josh McDonald" <[EMAIL PROTECTED]> wrote:
> >
> > Right, I see. I suppose you may be doing something funky in the
> constructor
> > for your actual impl of A or B. Try commenting out the constructor
> and see
> > if you have the same problem.
> >
> > -Josh
> >
> > On Tue, Sep 9, 2008 at 9:17 AM, dmiramontesval
> > <[EMAIL PROTECTED]>wrote:
> >
> > > They keys in the Java map are Strings and the values are B objects,
> > > you could say it is HashMap.
> > > So suppose in Java i do this:
> > >
> > > A objectA = new A();
> > > objectA.myMap = new HashMap();
> > > B objectB1 = new B();
> > > objectB1.id = 1;
> > > objectB1.name = "Test";
> > > myMap.put("key1", objectB1);
> > >
> > > In Flex if i iterate over the myMap property:
> > >
> > > for each(var i:* in objectA.myMap) {
> > >   if (i is B) {
> > >  trace(i.id + " " + i.name);
> > >   }
> > > }
> > >
> > > Doing this resets the B object inside myMap, so the trace prints NaN
> > > and empty string.
> > >
> > > If i dont use an instance of B:
> > >
> > > for each(var i:* in objectA.myMap) {
> > >   if (!(i is A)) {
> > >  trace(i.id + " " + i.name);
> > >   }
> > > }
> > >
> > > The trace prints 1 Test.
> > >
> > > The main issue is that if i create an instance of B anywhere in my
> > > code, the B object inside myMap resets.
> > >
> > > The second issue is that inside the myMap property there are two
> > > objects instead of just one, this additional object is a reference to
> > > A and its key is "owner", so the myMap property looks like:
> > >
> > > var myMap:Object = {owner:the A object, key1: the B object};
> > >
> > >
> > > I have no idea where this reference to the A object comes from, but i
> > > can live with that, the main issue is that i can't use the B class
> > > because if i do the B objects inside the map are reset.
> > >
> > >
> > > --- In flexcoders@yahoogroups.com, "Josh McDonald"  wrote:
> > > >
> > > > The problem I think is you're using the wrong data structures.
> > > >
> > > > If your Java map looks like this:
> > > >
> > > > HashMap myMap;
> > > >
> > > > What you'll get in Flex isn't what you've got below, it's an
> object like
> > 

Re: [flexcoders] Re: Issue when converting HashMap(Java) into Object (ActionScript)

2008-09-08 Thread Josh McDonald
Right, I see. I suppose you may be doing something funky in the constructor
for your actual impl of A or B. Try commenting out the constructor and see
if you have the same problem.

-Josh

On Tue, Sep 9, 2008 at 9:17 AM, dmiramontesval
<[EMAIL PROTECTED]>wrote:

> They keys in the Java map are Strings and the values are B objects,
> you could say it is HashMap.
> So suppose in Java i do this:
>
> A objectA = new A();
> objectA.myMap = new HashMap();
> B objectB1 = new B();
> objectB1.id = 1;
> objectB1.name = "Test";
> myMap.put("key1", objectB1);
>
> In Flex if i iterate over the myMap property:
>
> for each(var i:* in objectA.myMap) {
>   if (i is B) {
>  trace(i.id + " " + i.name);
>   }
> }
>
> Doing this resets the B object inside myMap, so the trace prints NaN
> and empty string.
>
> If i dont use an instance of B:
>
> for each(var i:* in objectA.myMap) {
>   if (!(i is A)) {
>  trace(i.id + " " + i.name);
>   }
> }
>
> The trace prints 1 Test.
>
> The main issue is that if i create an instance of B anywhere in my
> code, the B object inside myMap resets.
>
> The second issue is that inside the myMap property there are two
> objects instead of just one, this additional object is a reference to
> A and its key is "owner", so the myMap property looks like:
>
> var myMap:Object = {owner:the A object, key1: the B object};
>
>
> I have no idea where this reference to the A object comes from, but i
> can live with that, the main issue is that i can't use the B class
> because if i do the B objects inside the map are reset.
>
>
> --- In flexcoders@yahoogroups.com, "Josh McDonald" <[EMAIL PROTECTED]> wrote:
> >
> > The problem I think is you're using the wrong data structures.
> >
> > If your Java map looks like this:
> >
> > HashMap myMap;
> >
> > What you'll get in Flex isn't what you've got below, it's an object like
> > this:
> >
> > var mymap : Object =
> >   {
> > 1: "String 1",
> > 2: "String 2",
> > 79: "Blue"
> >   }
> >
> > Not the structure that you're trying to coerce it to based on the
> code you
> > posted. But since this is clearly just "example" Flex code and I have no
> > idea about what your Java looks like, I'm just guessing.
> >
> > -Josh
> >
> > On Tue, Sep 9, 2008 at 8:46 AM, dmiramontesval
> > <[EMAIL PROTECTED]>wrote:
> >
> > > I have this weird issue and i can't figure it out, let me explain:
> > >
> > > I have a java object A which has a HashMap variable myMap, this map
> > > will hold objects of class B. In ActionScript i have the corresponding
> > > class A which has a variable myMap but since there is no HashMap in
> > > ActionScript its type is Object and i also have the corresponding
> class B.
> > >
> > > [RemoteClass(alias="com.test.A")]
> > > public class A {
> > >  public var myMap:Object; // this is the HashMap in Java
> > > }
> > >
> > > [RemoteClass(alias="com.test.B")]
> > > public class B {
> > >  public var id:Number;
> > >  public var name:String;
> > > }
> > >
> > > I need to put the objects B contained in the map inside a DataGrid so
> > > i am obtaining the object of class A using a RemoteObject and then i
> > > iterate over the myMap property using a for each in loop, like this:
> > >
> > > for each(var i:* in objectA.myMap) {
> > > someArrayCollection.add(i);
> > > }
> > >
> > > The first issue appears here, suppose the java HashMap contains 3
> > > elements, in the ActionScript loop i get 4 elements, the fourth one
> > > being a reference to the A object (its key appears as "owner"). In
> > > order to avoid this i use the "is" operator like this:
> > >
> > > for each(var i:* in objectA.myMap) {
> > >   if (i is B) {
> > > someArrayCollection.add(i);
> > >   }
> > > }
> > >
> > > Now here is the real issue, when i do this the B objects contained in
> > > the myMap property are reset to their initial values (NaN and empty
> > > string according to the B class). I changed the if condition to this
> > > and worked:
> > >
> > > for each(var i:* in objectA.myMap) {
> > >   if (!(i is A)) {
> > >someArrayCollection.add(i);
> > >   }
> > > }
> > > When i did this the DataGrid shows the elements in the
> > > someArrayCollection perfectly fine. I did a little more testing and i
> > > "figured" out the issue, if i use an instance of class B anywhere in
> > > my application, the values of the B objects inside the myMap property
> > > are reset, for example:
> > >
> > > for each(var i:* in objectA.myMap) {
> > >   if (i is B) {
> > >  someArrayCollection.add(i);
> > >   }
> > > }
> > > var test:B = new B();
> > >
> > > This resets the B objects inside the myMap property of the A object
> > > which makes no absolute sense, this is why when i used the B class in
> > > the if condition the objects reset their values.
> > >
> > > So the thing is whenever i use the B class, which is the class of the
> > > objects inside myMap, the B objects are reset Does anyone know how
> > > to fix this?
> > >
> > > I am using Flex 2.01 hotfix 3, i wonde