This would be my approach:

You need two dataProviders (ArrayCollections), one being for the available 
modules and the other for your list of staff. You'd only need two remote 
objects to retrieve them.

Your modules dataprovider would be passed into each component instance and used 
by the component to generate your list of available modules with checkboxes.  

Your repeater is going to accept the staff list dataProvider.  As it loops over 
the ArrayCollection, it will pass the selected modules for a given staff member 
to your checkbox component. It's up to you to write the setter function to pass 
the selected values into your checkbox component and to set the 'selected' 
property of each checkbox accordingly.  

Jeff

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf 
Of valdhor
Sent: Monday, July 27, 2009 2:22 PM
To: [email protected]
Subject: [flexcoders] Re: better option than repeater?

I don't quite get what you are trying to do.

Create a component. This component will display each staff member. Create a 
public variable to hold each staff record (Value Object) and pass that record 
to the component inside the repeater. The example I posted shows how to do this.

So, there is only one call to the RemoteObject service that returns an array 
collection of staff objects. The data provider of the repeater is set to this 
array collection. As the repeater runs, each instance of the component gets one 
staff record. You use this record to figure out which checkbox is to be set.

An mx:RemoteObject can be used wherever you need it. I have components with 
Remote Objects that are repeated. The first remote object call gets the data 
for each component which then makes its own RO call to get further data if the 
user selects that component. As an example, in your situation, you could have 
each staff member displayed with a button labeled "More Info". If a user clicks 
this button the RO in this component will make a call to the server to get more 
info for this staff member.


HTH



Steve




--- In [email protected], "postwick" <p...@...> wrote:
>
> OK, thanks to the below example, I have made some progress on setting up
> my first custom itemRenderer.  Code can be viewed here: 
> http://www.ubeek.com/Flex/testrend.mxml
> 
> As I mentioned before, my goal is to display a list of Staff.  One of
> the fields (moduleAccess) in the Staff record is a list of integers
> (i.e.  "1,3,17,25").  I have a table that contains a list of modules
> (SEQ, MODULENAME).  For each Staff displayed by the List's itemRenderer,
> I need to loop through all the modules and output a checkbox...and if
> the module's SEQ is in the Staff's moduleAccess list then the box should
> be checked.
> 
> I tried setting up a remoteObject inside the custom renderer, but no
> matter where I put it it gave me a parse error.  I guess it doesn't like
> mx:RemoteObject inside a component.  So I put it outside the component,
> but then the script function inside the component didn't seem able to
> access the RemoteObject's data.  Although it was what I initially tried
> to do (with the RO inside the component) I don't really want to do that
> as it seems highly inefficient to query the database for every Staff
> record.  It seems I should be able to execute the RO just once and then
> pass the resulting list of modules to the component so I can loop
> through it to output all the checkboxes (and for each record check the
> SEQ against the Staff's moduleAccess, which I know how to do).
> 
> So the question is - how do call the RO just once and pass the result
> into the component (as an ArrayCollection or something) so I can loop
> over it repeatedly instead of actually calling it and hitting the
> database repeatedly?
> 
> Thanks,
> Paul
> 
> 
> --- In [email protected], "valdhor" <valdhorlists@> wrote:
> >
> > As a quick and dirty...
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > layout="vertical"
> >      xmlns:custom="Components.*">
> >      <mx:Script>
> >          <![CDATA[
> >              import mx.collections.ArrayCollection;
> >
> >              [Bindable] private var staffArrColl:ArrayCollection;
> >          ]]>
> >      </mx:Script>
> >      <mx:Repeater id="myStaff" dataProvider="{staffArrColl}">
> >          <custom:CheckBoxComponent id="checkBoxs"
> > person="{Person(myStaff.currentItem)}" />
> >      </mx:Repeater>
> > </mx:Application>
> >
> > CheckBoxComponent.mxml:
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml";
> > creationComplete="onCreationComplete()">
> >      <mx:Script>
> >          <![CDATA[
> >              import ValueObjects.Person;
> >
> >              public var person:Person;
> >
> >              private function onCreationComplete():void
> >              {
> >                  // From person object make a remote object call to
> get
> > Modules and Queues
> >                  // When remote object calls return, create checkboxes
> > appropriately
> >              }
> >          ]]>
> >      </mx:Script>
> > </mx:VBox>
> >
> > Person.as:
> > package ValueObjects
> > {
> >      [RemoteClass(alias="Classes.Testing.Person")]
> >      [Bindable]
> >      public class Person
> >      {
> >          //instance variables
> >          private var _name:String;
> >          private var _id:String;
> >
> >          //accessor methods
> >          public function get name():String {return _name;}
> >          public function get id():String {return _id;}
> >
> >          //mutator methods
> >          public function set name(name:String):void {_name = name;}
> >          public function set id(id:String):void {_id = id;}
> >      } // end class
> > }//end package
> >
> > I have not included any remote object calls or result handlers. I'll
> > leave that up to you.
> >
> > Keep in mind that Flex is object oriented. One of the ideas behind OOP
> > is encapsulation. If you can encapsulate all the properties and
> methods
> > of something and then repeat that, the possibilities are endless.
> >
> >
> > HTH
> >
> >
> >
> > Steve
> >
> > --- In [email protected], "postwick" paul@ wrote:
> > >
> > > Can you give me a brief example of code that would achieve the part
> > where you say "create a component"?
> > >
> > > Keep in mind the number of checkboxes and their labels is not
> static.
> > There are three tables involved: staff, modules, and queues.  The
> > checkboxes are created dynamically from the records returned from the
> > modules and queues tables.
> > >
> > > --- In [email protected], "valdhor" valdhorlists@ wrote:
> > > >
> > > > I use repeaters quite a lot and like them.
> > > >
> > > > What I do is to create a component (Which sometimes contains other
> > components) and the repeat that.
> > > >
> > > > In your situation, I would create a component with all of your
> check
> > boxes and save button. This component would have all of the
> > functionality to display which check boxes are selected as well as the
> > save button click handler. It would also have a public property that
> > would take a data object. On creation complete of this component, it
> > would check the values of the data object and set the check boxes
> > appropriately.
> > > >
> > > > Then, I would repeat this component passing in the data objects
> > returned from the remote object call...
> > > >
> > > > <mx:Repeater id="myStaff" dataProvider="{staffArrColl}">
> > > > <custom:CheckBoxComponent id="checkBoxs"
> > person="{Person(myStaff.currentItem)}" />
> > > > </mx:Repeater>
> > > >
> > > >
> > > > HTH
> > > >
> > > >
> > > >
> > > > Steve
> > > >
> > > >
> > > > --- In [email protected], "postwick" <paul@> wrote:
> > > > >
> > > > > I don't like repeaters.  They are too clumsy.  The biggest
> > drawback is an inability to access values after the repeater has
> finish
> > executing.  It's not the same as, for example, looping over values and
> > generating static HTML using ColdFusion.  I seem to always end up
> having
> > to navigate up and down through the parents/children of the objects
> and
> > storing values I need in properties like name, automationName, etc.
> > This is clumsy and messy.
> > > > >
> > > > > As an example, I have a section of my application where I want
> to
> > list the names of people from a table, and for each person generate a
> > set of checkboxes that designate access to certain areas of the
> > application.  For example:
> http://www.ubeek.com/images/staffrepeater.jpg
> > > > >
> > > > > That is one main repeater that loops through the staff (records
> > returned from remoteObject) and inside that repeater two other
> repeaters
> > (also from remoteObjects) that generate the checkboxes.
> > > > >
> > > > > I can't simply pass the primary key of the staff for which the
> > Save button was clicked, by putting
> > click="saveClick({staffRepeater.currentItem.SEQ})" into the button
> > object.  When I do that and click it I get an error about "repeater is
> > not currently executing" or something like that.
> > > > >
> > > > > I don't want to resort to a datagrid and then "click to edit"
> then
> > bring up a form kind of process.  I want it as few clicks as possible.
> > > > >
> > > > > Is there a better way to display data in a custom way like this,
> > without using repeaters, so that I can more easily access the child
> > objects and their properties?
> > > > >
> > > > > Thanks,
> > > > > Paul
> > > > >
> > > >
> > >
> >
>




------------------------------------

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Alternative FAQ location: 
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! 
Groups Links



Reply via email to