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 flexcoders@yahoogroups.com, "valdhor" <valdhorli...@...> 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 flexcoders@yahoogroups.com, "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 flexcoders@yahoogroups.com, "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 flexcoders@yahoogroups.com, "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
> > > >
> > >
> >
>

Reply via email to