It isn't a case of need.  One reason you might *want* to have public
members in your POJO is for convenience.  Flex will automatically
handle conversion of Java strings (as well as several other types;
check the documentation) to actionscript, so if your RemoteObject
returns a collection of POJOs with public String members you can plug
that list directly into a grid's dataprovider without any extra
actionscript code.  This would correspond to collections of ClassA and
ClassB objects, which map nicely to what dataProviders expect.  You
cannot, however, pass a list of Class1 POJOs and expect the datagrid
to display Class1.ClassA.A1, Class1.ClassB.B1, etc., without doing
some extra work on the actionscript side.  See the difference?

Now, this doesn't mean you *have* to do things either one way or
another.  I'm just trying to explain what I personally think is the
easiest way to get POJO data into a dataGrid in Flex.  If this still
isn't clear, let me know and I'll try to provide some working code.

Hope that helps!

Doug

--- In [email protected], "sshriyan27" <[EMAIL PROTECTED]> wrote:
>
> Thanks guys for helping me out here, but still i don't understand 
> why should i need to have public members firstname,lastname etc in 
> the CloserResultsForm form, isn't it involves redundancy and hard to 
> maintain lots of member variables. 
> 
> all i want is this,
> 
> Class1 instanciate class A, class B, Class A has member variables 
> A1,A2 and Class B has B1,B2 etc,
> if i want to display A1, B1 values using Class1, 
> i should be saying classA.A1,classA.A2, ClassB.B1, ClassB.B2 etc,
> i don't want to declare A1,A2 in Class1 again in 2 palces.
> Am i missing something here about my design pattern? May be i'm 
> confused.
> Pls help me soon.
> 
> --- In [email protected], "douglowder" <douglowder@> 
> wrote:
> >
> > You're almost there!  What you want is for CloserDataAccess to 
> return
> > a list of objects that contain firstname and lastname properties. 
> > What you have now is a list of objects that contain other objects 
> (the
> > UserProfileForms), which then contain firstname and lastname.
> > 
> > If your CloserResultsForm java class had public members firstname 
> and
> > lastname, initialized by calling the proper getters from
> > UserProfileForm, your datagrid should work.  This wouldn't even
> > require the separate ActionScript classes for CloserResultsForm and
> > UserProfileForm.
> > 
> > 
> > Doug
> > 
> > 
> > --- In [email protected], "sshriyan27" <[EMAIL PROTECTED]> 
> wrote:
> > >
> > > Thanks but still not working i made them private now.
> > > I'm totally lost with action script and object mapping.
> > > Do i need to use action script for the value objects i have, if 
> that 
> > > so is there any easy way to write action scripts same as the 
> java 
> > > objects. 
> > > 
> > > 
> > > <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"; 
> > > initialize="initApp()" xmlns:i2view="view" pageTitle="Test 
> > > Application">
> > >           
> > >  <mx:Script>
> > >   import src.com.flex.form.*;
> > >   
> > >   var users: Array;
> > >   var upForm: UserProfileForm;
> > >   var closerResultsForm: CloserResultsForm;
> > >   var userList: Array;
> > >   var resultList: Array;
> > >   
> > >         function initApp() {
> > >            ro.getResults(); // returns CloserResultsForm as a 
> > > collection
> > >              
> > >   }
> > > 
> > >         function getUserList_result(event) {
> > >             userList=event.result;
> > >   }
> > >           
> > >   function getResultList_result(event) {
> > >            resultList=event.result;
> > >              
> > >         }
> > >    
> > > 
> > > </mx:Script>
> > >  
> > >  <mx:RemoteObject id="ro" 
> > > source="com.chl.dataaccess.CloserDataAccess">
> > >     <mx:method name="getResults" result="getResultList_result
> > > (event)"/> 
> > > </mx:RemoteObject>
> > >  
> > > <mx:DataGrid id="dg" dataProvider="{resultList}" width="838"  
> > > editable="true" showHeaders="true">
> > >             <mx:columns>
> > >               <mx:Array>  
> > >                 <mx:DataGridColumn columnName="firstname" 
> > > headerText="Firstname"/>
> > >                 <mx:DataGridColumn columnName="lastname" 
> > > headerText="Lastname"/>
> > >               </mx:Array> 
> > >       </mx:columns>        
> > > </mx:DataGrid>
> > > 
> > > 
> > > ** This is the situation i'm in now, we're going to develop new 
> apps 
> > > using RIA technology, we don't have time to learn action scripts 
> or 
> > > any other vedor specific scripts. so i'm trying to convince that 
> > > flex is the best solution, but it looks like flex dev is not 
> rapid 
> > > as what i saw from demo, still lots of manual coding has to be 
> done. 
> > > May be i'm not understanding fully about flex.
> > > 
> > > So can you guys tell me whether i should use flex or coldfushion 
> or 
> > > ajax with struts as i did before.
> > >  
> > > Thanks
> > > 
> > > 
> > > --- In [email protected], "douglowder" 
> <[EMAIL PROTECTED]> 
> > > wrote:
> > > >
> > > > Ah, it looks like you have taken both my *and* Dave's advice, 
> when 
> > > you
> > > > really only needed to do one or the other.  So, if you don't 
> have a
> > > > problem with making your firstname and lastname variables 
> public in
> > > > your UserProfileForm POJO (which you might, since it kind of 
> > > defeats
> > > > the purpose of getters and setters), then just pass your 
> datagrid a
> > > > collection of UserProfileForms:
> > > > 
> > > >    <mx:DataGrid dataProvider="{myUserProfileFormCollection}" />
> > > > 
> > > > This will display the entire object in the datagrid.  If you 
> only 
> > > want
> > > > to see certain fields, or want to specify a specific order, 
> define
> > > > columns for the datagrid like so:
> > > > 
> > > >    <mx:DataGrid dataProvider="{myUserProfileFormCollection}">
> > > >         <mx:columns>
> > > >             <mx:Array>
> > > >                 <mx:DataGridColumn columnName="firstname"
> > > > headerText="First Name"/>
> > > >                 <mx:DataGridColumn columnName="lastname"
> > > > headerText="Last Name"/>
> > > >             </mx:Array>
> > > >         </mx:columns>
> > > >    </mx:DataGrid>
> > > > 
> > > > If, however, you want to keep the members variables of your 
> objects
> > > > hidden and provide access only through getters and setters, 
> then
> > > > change the declarations back to private and follow Dave's 
> advice.
> > > > 
> > > > I hope that helps!
> > > > 
> > > > Doug
> > > > 
> > > > --- In [email protected], "sshriyan27" 
> <[EMAIL PROTECTED]> 
> > > wrote:
> > > > >
> > > > > Let me send you all my classes, i don't still understand! 
> Thanks 
> > > for 
> > > > > your help anyway.
> > > > >  
> > > > > public class UserProfileForm {
> > > > > 
> > > > >       public String firstname=null;
> > > > >       public String lastname=null;
> > > > >        
> > > > >         public UserProfileForm(){}
> > > > > 
> > > > >       public String getFirstname() {
> > > > >               return firstname;
> > > > >       }        
> > > > >       public void setFirstname(String firstname) {
> > > > >               this.firstname = firstname;
> > > > >       }
> > > > >       public String getLastname() {
> > > > >               return lastname;
> > > > >       }
> > > > >       public void setLastname(String lastname) {
> > > > >               this.lastname = lastname;
> > > > >       }
> > > > >        
> > > > > }
> > > > > 
> > > > > public class CloserResultsForm implements Serializable{
> > > > >       public UserProfileForm userProfileForm;
> > > > >       
> > > > >       public CloserResultsForm(){
> > > > >         userProfileForm=new UserProfileForm();
> > > > >       }
> > > > >       public UserProfileForm getUserProfileForm() {
> > > > >               return userProfileForm;
> > > > >       }
> > > > >       public void setUserProfileForm(UserProfileForm 
> > > > > userProfileForm) {
> > > > >               this.userProfileForm = userProfileForm;
> > > > >       }
> > > > >       
> > > > > }
> > > > > 
> > > > > ** my dataaccess returns collection of CloserResultsForm 
> > > > > 
> > > > > CloserResultsForm.as file
> > > > > class src.com.flex.form.CloserResultsForm{
> > > > >       public var userProfileForm : UserProfileForm;
> > > > >       
> > > > >       static var registered=Object.registerClass
> > > > > ("com.chl.form.CloserResultsForm", 
> > > > > src.com.flex.form.CloserResultsForm);
> > > > >        
> > > > >         public function CloserResultsForm(){
> > > > >                 this.userProfileForm=new UserProfileForm();
> > > > >         }
> > > > > }
> > > > > 
> > > > > UserProfileForm.as file
> > > > > class src.com.flex.form.UserProfileForm{
> > > > >   public  var firstname:String;
> > > > >     public  var lastname:String;
> > > > >       public var _remoteClass;
> > > > >     static var registered=Object.registerClass
> > > > > ("com.chl.form.UserProfileForm", 
> > > src.com.flex.form.UserProfileForm);
> > > > >        
> > > > > } 
> > > > > 
> > > > > How do i print the firstname and lastname in datagrid, am i 
> > > missing 
> > > > > something here.
> > > > > 
> > > > > --- In [email protected], "Dave Wolf" 
> <[EMAIL PROTECTED]> 
> > > wrote:
> > > > > >
> > > > > > Ahh yes, the same J2EE struggles with property setting.  
> As 
> > > Doug 
> > > > > says
> > > > > > you do not want to be calling a million setters on a 
> remote 
> > > object.
> > > > > > You are better off refactoring this to either create a new 
> > > Value
> > > > > > Object, or to treat your existing class itself as a value 
> > > object.  
> > > > > > 
> > > > > > So rather then getting a remote reference to say 
> > > UserProfileForm, 
> > > > > then
> > > > > > calling a million getters and setters, I would create a 
> POJO 
> > > which
> > > > > > returns the UserProfileForm as a return type.  Then call 
> all 
> > > your
> > > > > > setters locally, and pass it back up to the server as the 
> > > > > parameter to
> > > > > > another POJO method call.
> > > > > > 
> > > > > > The second option is to add a new Value Object property to 
> the
> > > > > > UserProfileForm.  Again create the stub, call all the 
> setters 
> > > on 
> > > > > the
> > > > > > local value object, then call one call on the 
> UserProfileForm 
> > > to
> > > > > > return this coarsly grained Value Object.
> > > > > > 
> > > > > > You need to keep network calls in mind in your 
> architecture.  
> > > > > There is
> > > > > > a graveyard filled with failed J2EE projects who ignored 
> the 
> > > > > network
> > > > > > and the effects of not architecting around seriously 
> reducing 
> > > the
> > > > > > number and size of remote calls.
> > > > > > 
> > > > > > -- 
> > > > > > Dave Wolf
> > > > > > Cynergy Systems, Inc.
> > > > > > Macromedia Flex Alliance Partner
> > > > > > http://www.cynergysystems.com
> > > > > > 
> > > > > > Email:  [EMAIL PROTECTED]
> > > > > > Office: 866-CYNERGY
> > > > > > 
> > > > > > 
> > > > > > --- In [email protected], "douglowder" 
> > > <[EMAIL PROTECTED]> 
> > > > > wrote:
> > > > > > >
> > > > > > > Flex 1.5 does a pretty good job of automatically 
> translating 
> > > > > Java 
> > > > > > > types to ActionScript, but only for members that are 
> > > declared 
> > > > > > > public, not private.  So, if you want to continue using 
> your 
> > > > > getter 
> > > > > > > routines for private members in your existing classes, 
> be 
> > > > > prepared 
> > > > > > > to make a lot of calls to your remote object.  You could 
> > > also 
> > > > > create 
> > > > > > > a new "facade" Java class for mapping purposes, which 
> would 
> > > have 
> > > > > > > public members for all the variables you want to expose 
> to 
> > > > > > > ActionScript, and have that class make all the calls to 
> your 
> > > > > > > existing class's getters to initialize those public 
> > > members.  
> > > > > You 
> > > > > > > can then refer to the variables by name (the same name 
> as in 
> > > the 
> > > > > > > Java class) from within ActionScript.
> > > > > > > 
> > > > > > > Another thing to keep in mind is that datagrids expect 
> to be 
> > > > > passed 
> > > > > > > arrays (actually, anything that implements the 
> DataProvider 
> > > > > > > interface) of objects, not a single object.  If your 
> Java 
> > > calls 
> > > > > are 
> > > > > > > returning a single object instead of a list of objects, 
> use 
> > > > > > > mx.utils.ArrayUtil.toArray() on the result to convert it 
> to 
> > > an 
> > > > > array 
> > > > > > > in ActionScript.
> > > > > > > 
> > > > > > > Doug
> > > > > > > 
> > > > > > > 
> > > > > > > --- In [email protected], "sshriyan27" 
> > > > > <[EMAIL PROTECTED]> 
> > > > > > > wrote:
> > > > > > > >
> > > > > > > > I'm new to Flex we're trying evaluate in our company 
> > > whether 
> > > > > we 
> > > > > > > > should use FLEX or not. Right we have Java, Struts 
> based 
> > > > > > > application.
> > > > > > > > 
> > > > > > > > I have a simple question, i have an Object and still 
> > > strugling 
> > > > > to 
> > > > > > > > map that to an action script and datagrid.
> > > > > > > > How do i display values of UserProfileForm in 
> datagrid, 
> > > like 
> > > > > in 
> > > > > > > > Struts i used to do  
> > > > > CloserResultsForm.userProfileForm.firstname
> > > > > > > (); 
> > > > > > > > Can some one explain this to me. 
> > > > > > > > ** I can get the Single object to get displayed but 
> not 
> > > the 
> > > > > > > > inhertited ones.
> > > > > > > > 
> > > > > > > > public class CloserResultsForm implements Serializable{
> > > > > > > >         private UserProfileForm userProfileForm;
> > > > > > > > }
> > > > > > > > 
> > > > > > > > public class UserProfileForm {
> > > > > > > >         private String username=null;
> > > > > > > >         private int userid;
> > > > > > > >         private String password=null;
> > > > > > > >         private String firstname=null;
> > > > > > > >         private String lastname=null;
> > > > > > > >         private String roleName=null;
> > > > > > > >          
> > > > > > > >     public UserProfileForm(){
> > > > > > > >          
> > > > > > > >     }
> > > > > > > >  .... // then getters and setters for the above
> > > > > > > > }
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
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