Is myValue on oNewItem a complex type or is it expected to return a
simple value?

Does the constructor of com.MyPojo take any arguments? If so, does it
look something like this?

public class com.MyPojo
{
        public var myValue:String;

        public function MyPojo(mval:String, someval:Object ...)
        {
                myValue = mval;
                // set other vals...
        }
}

If so, then you're getting bitten by the deserialziation order of the
Flash Player for complex types. When the player is recreated instances
of types from their serialized form (be it AMF, RTMP, LSOs), it first
creates a shell instance from the type, sets the state, then calls the
real constructor (with no args defined). This is by design because
serialized objects can't pass constructor arguments so by setting them
first you get a chance to access them during object initialization...
but it does mean that blindly setting the values from constructor
arguments is dangerous as it will override the member variables with
undefined (as no arguments were passed to the constructor).

Try this check first:

public class com.MyPojo
{
        public var myValue:String;

        public function MyPojo(mval:String, someval:Object ...)
        {
                if (mval != undefined)
                {
                        myValue = mval;
                        // set other vals...
                }
        }
}

(Note: For the keen AS2-savvy engineers out there, you could use the 
!== or "strict not-equal" operator to allow for null values to be passed
to constructors when not being initialized by deserialization).


-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Kevin Ewok
Sent: Friday, May 27, 2005 2:34 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Converting Java POJO to Actionscript Errors

OK...i've gotten a lot further. I found an Ant script to create my AS
classes from my POJOs (maintaining inheritance). I registered the
classes and it compiles fine. THe problem is still there but it looks
like the POJO being returned from myRemoteObject is not being
converted to it's AS counterpart. When I debug, the 'result' is
'undefined'. I debugged my Service class and I see the data is there.
What am I doing wrong where the AS class is not getting populated
correctly? Is it because I have my dataprovider set to a remoteObject
result? Should I set another varaible for that? Thanks....


<mx:Script>
<![CDATA[               
  import com.*;
  var oNewItem: MyPojo;
   
   function addToDataGrid() {
   oNewItem = myRemoteObj.getNewPojo();
   trace(oNewItem);  // prints in log-->  [object Object]
   trace(oNewItem.myValue); // prints --> undefined 
   dg.addItem(oNewItem); //still a blank row
}
....
</mx:Script> 

<mx:DataGrid id="dg" dataProvider="{myRemoteObj.getAll.result}">


--- In flexcoders@yahoogroups.com, "Kevin Ewok" <[EMAIL PROTECTED]> wrote:
> Pete-
>   Thanks....to answer your confusion...Suzy and Kevin are the same
> person, when I registered, the wrong username got auto-populated when
> I joined flexcoders and there's no profile for me to fix it.
> 
> Getting back to your response (thanks by the way), I've tried
> assigning the returned remote object to a general AS object (see
> example below)...that does not work....that's what causing these
> errors. I tried issuing the Object.registerClass() method to my Java
> POJO w/i my mxml file where I load the Datagrid...that does not work
> either. I guess I will be forced to write the AS class that matches my
> POJO...this is probbaly going to be annoying since my POJO is an
> object graph and involves inheritance....writing the same class twice
> seems like a poor design to me. I see there are some Ant scripts out
> there that do this, but they don't generate the class for me if there
> is inheritance. I would think there's a way I can just plug the
> returned single POJO in the datagrid....after all, the datagrid was
> first populated with an array of the SAME POJOs w/o having to register
> any classes!! I think I'm getting a head-ache!!
> 
> --- In flexcoders@yahoogroups.com, "Peter Farland" <[EMAIL PROTECTED]>
wrote:
> > (Hi suzy, firstly, I'm a little confused as to how Kevin Ewok's
response
> > turned into your message - are you saying you're having the same
issue
> > as Kevin? Let me first comment on Kevin's issue which will provide
good
> > background for yours...).
> > 
> > On looking again at the warning Keven is getting from ClassUtil it
means
> > that he didn't link in the com.MyPojo class to his SWF... that is,
the
> > compiler didn't include the AS class because it wasn't referenced
> > anywhere. 
> > 
> > Having a dummy variable of com.MyPojo type is one way to cause a
> > dependency on that class to have it compiled and linked in to the
SWF.
> > But, furthermore, by using Object.registerClass() you can avoid the
> > ClassUtil issue altogether because the player will attempt to create
> > types for you from the registerd information while processing the
AMF
> > response before the ClassUtil gets a chance to look at the result.
> > 
> > The ClassUtil is a legacy system from Flex 1.0 SOAP-based
RemoteObject
> > (which is not supported in Flex 1.5) where by you could use a
special
> > "_remoteClass" property to map client/server types since
> > Object.registerClass wasn't useful for non-AMF communication (i.e.
XML
> > transactions are just strings and thus don't' get processed by the
> > player). Since Flex 1.5 RemoteObject only uses AMF, the _remoteClass
> > method is not suggested for Flex 1.5 and you should use
> > Object.registerClass().
> > 
> > Now, for Suzy's question...
> > 
> > Essentially what you're looking for here is that Remote POJOs turn
into
> > plain old dynamic Objects on the client, right?
> > 
> > The problem is that in Flex 1.5 RemoteObject still has the
deprecated
> > "_remoteClass" property in the response (which you should be able
to see
> > in the AMF trace output). 
> > 
> > The old ClassUtil is designed to always do this translation for you
if
> > it finds the "_remoteClass" property... that is, it expects that
typed
> > POJOs map to a corresponding AS type (that must be available at
runtime
> > from the SWF).
> > 
> > By calling Object.registerClass you could bypass the ClassUtil's
> > translation attempt altogether... and, actually here's an idea,
perhaps
> > you can trick the player into registering your remote POJO class
to just
> > plain old Object to get a dynamic object back?
> > 
> > Pete
> > 
> > 
> > -----Original Message-----
> > From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On
> > Behalf Of suzy lawson
> > Sent: Friday, May 27, 2005 11:44 AM
> > To: flexcoders@yahoogroups.com
> > Subject: RE: [flexcoders] Converting Java POJO to Actionscript
Errors
> > 
> > Hari, 
> >   Thanks...I'll give this a shot. So my question is,
> > why do I have to write a matching AS class to match my
> > POJO? When I populate my Datagrid from the remote
> > object (arraylist of POJOs), I din't have to write any
> > AS classes.
> > 
> > --- "Doodi, Hari - BLS CTR" <[EMAIL PROTECTED]> wrote:
> > 
> > > Hi,
> > >   First couple of questions - did you register your
> > > POJO with AS class
> > > using Object.registerClass( ) method? 
> > >   What is the constructor method of you Pojo ?
> > > After both of above are in place(implemented) then
> > > you can create new object
> > > of your POJO type and assign your newly returned
> > > object to it and then add
> > > this new object to your datagrid using
> > > myDataGrid.addItem( );
> > > 
> > > This is what I did.....
> > > AS class looks like
> > > class classes.MyPojo
> > > {
> > >     public var myArray:Array;
> > >     private static var registered:Boolean =
> > > Object.registerClass("full path
> > > of you java class goes here", classes. MyPojo);     
> > >   
> > > }
> > >  In my MXML.... you can ignore statements which sets
> > > initial attribute
> > > values 
> > > function addRow()
> > >   {
> > >           var oNewItem:Object = new MyPojo ();  
> > >         oNewItem.adj_num = "12 ";                
> > >         oNewItem.adj_type = " ";
> > >         oNewItem.adj_category = " ";
> > >         oNewItem.adj_amt_terms_desc = " Doodi";
> > >         oNewItem.adj_reporter_applied_flag = "N";
> > >         oNewItem.adj_sign = "Additive";
> > >         oNewItem.adj_factor = " ";
> > >         oNewItem.adj_order_applied = "12";
> > > 
> > >           myDataGrid.addItem(oNewItem);
> > >                           
> > >           focusNewRow();
> > >           doLater(this,"focusNewRow");
> > >   }
> > > Thanks!
> > > Hari
> > > 
> > > -----Original Message-----
> > > From: flexcoders@yahoogroups.com
> > > [mailto:[EMAIL PROTECTED] On
> > > Behalf Of suzy lawson
> > > Sent: Friday, May 27, 2005 10:22 AM
> > > To: flexcoders@yahoogroups.com
> > > Subject: RE: [flexcoders] Converting Java POJO to
> > > Actionscript Errors
> > > 
> > > Hari-
> > >   THanks for your response. I tried that but I got a
> > > compilation error that "there is no method with the
> > > name MyPojo". I suppose that means I have to
> > > manually
> > > write the underlying ActionScript class for my Java
> > > POJO?
> > > 
> > > That just seems like a really bad implementation
> > > design b/c if MyPojo Java class changes, then I have
> > > to manually change my ActionScript class. urr...what
> > > am I missing?! 
> > > 
> > > --- "Doodi, Hari - BLS CTR" <[EMAIL PROTECTED]> wrote:
> > > > Try this.....
> > > > 
> > > > <mx:script...>
> > > > var newObj:Object = new MyPojo(); // constructor
> > > of
> > > > your POJO
> > > > function addToGrid() {
> > > >   newObj = remoteObj.getNewJob();  
> > > >   myDataGrid.addItem(newObj); 
> > > > }
> > > > </mx:script>
> > > > 
> > > > Thanks!
> > > > Hari
> > > > 
> > > > -----Original Message-----
> > > > From: flexcoders@yahoogroups.com
> > > > [mailto:[EMAIL PROTECTED] On
> > > > Behalf Of Kevin Ewok
> > > > Sent: Friday, May 27, 2005 9:46 AM
> > > > To: flexcoders@yahoogroups.com
> > > > Subject: [flexcoders] Converting Java POJO to
> > > > Actionscript Errors
> > > > 
> > > > Gang-
> > > >   I'm a newbie and all the flexdocs on MM's site
> > > > couldn't give me a
> > > > concrete answer. I have a datagrid that is
> > > populated
> > > > from an ArrayList
> > > > of POJO's (using the remote object). That works
> > > > fine. 
> > > > 
> > > > I then have another method that is called 30
> > > seconds
> > > > later then
> > > > returns a single POJO (of the same type from the
> > > > POJOs returned in the
> > > > first method). I then try to add it to my datagrid
> > > > using the
> > > > myDatagrid.addItem(newObj), but I get the below
> > > > debug error.
> > > > 
> > > > Warning: Reference to undeclared variable,
> > > > '_global.com.MyPojo'
> > > >         at mx_utils_ClassUtil::findClass()
> > > > Warning: valueOf is not a function
> > > >         at mx_utils_ClassUtil::getFlexClass() 
> > > > 
> > > > Is there a special way I need to declare 'newObj'
> > > > (which I pass into
> > > > the datagrid.addItem() method), or do I have to
> > > > explicity write the
> > > > AS-equilavent class of my Java POJO class?  
> > > > 
> > > > I would think Flex could convert this class for
> > > me,
> > > > but I'm obviously
> > > > missing an important step to add it to the
> > > > datagrid/dataprovider.
> > > > Thanks in advance for your help.
> > > > 
> > > > <mx:script...>
> > > > var newObj:Object;
> > > > function addToGrid() {
> > > >   newObj = remoteObj.getNewJob();  
> > > >   myDataGrid.addItem(newObj); 
> > > > }
> > > > </mx:script>
> > > > 
> > > > <mx:DataGrid id="myDataGrid"
> > > > dataProvider="{remoteObj.getAll.result}">
> > > > ...
> > > > 
> > > > 
> > > > 
> > > > 
> > > >  
> > > > Yahoo! Groups Links
> > > > 
> > > > 
> > > > 
> > > >  
> > > > 
> > > > 
> > > 
> > > 
> > >           
> > > __________________________________ 
> > > Do you Yahoo!? 
> > > Yahoo! Small Business - Try our new Resources site
> > > http://smallbusiness.yahoo.com/resources/
> > > 
> > > 
> > >  
> > > Yahoo! Groups Links
> > > 
> > > 
> > > 
> > >  
> > > 
> > > 
> > 
> > 
> > 
> >             
> > __________________________________ 
> > Do you Yahoo!? 
> > Yahoo! Small Business - Try our new Resources site
> > http://smallbusiness.yahoo.com/resources/
> > 
> > 
> >  
> > Yahoo! Groups Links




 
Yahoo! Groups Links



 




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to