5 Replies Latest reply on Oct 28, 2008 12:19 PM by Newsgroup_User

    DataProvider and itemEditEnd to the itemrenderer's set data()

    happybrowndog Level 1
      Hello,
      I'm hoping someone can give me some insight please.

      In a datagrid for which I have custom itemrenderers and an itemEditEnd event handler, I use the event handler to verify the value put into the cell and modify it. For example, if a user puts in a value that should be upper case, the value is modified to upper case and then the dataProvider's datasource (XMLList) is updated with the new value. Furthermore, the XML item that has the new value has an attribute added to it called "edited" with a value="true". The custom itemrenderer simply takes the data from the overridden set data() method and displays it in a particular color depending on the data.

      I am using the Flex builder debugger to step through every step of the way. When the ItemEditEnd event handler finishes processing, the debugger tells me that the datasource has been correctly updated with the modifications to the value (in this case, to upper case) and the attribute added. Then the debugger steps through to the custom itemrenderer's set data() method, which has an Object as an input parameter.

      I inspected that input parameter in the debugger and found that the entire row of the XML datasource is what that Object is. When I inspect that Object further, I find that the attribute added exists, but that the value that should have been modified is not - but is instead the original value put into the cell.

      1. What could possibly be going on here?
      2. Should modifications to the value entered be updated in the datasource when at the itemEditEnd event handler, or should they be done at the overriden set data() method of the itemrenderer?
      3. Would it be improper to get the instance of the custom renderer in the itemEditEnd event handler and stuff the modified value into it (in this case, the .text attribute of the subclassed TextInput)? What is wrong with this approach?

      Thanks for any insight you might have.
        • 1. Re: DataProvider and itemEditEnd to the itemrenderer's set data()
          Level 7

          "happybrowndog" <webforumsuser@macromedia.com> wrote in message
          news:ge57rc$hbb$1@forums.macromedia.com...
          > Hello,
          > I'm hoping someone can give me some insight please.
          >
          > In a datagrid for which I have custom itemrenderers and an itemEditEnd
          > event
          > handler, I use the event handler to verify the value put into the cell and
          > modify it. For example, if a user puts in a value that should be upper
          > case,
          > the value is modified to upper case and then the dataProvider's datasource
          > (XMLList) is updated with the new value. Furthermore, the XML item that
          > has
          > the new value has an attribute added to it called "edited" with a
          > value="true".
          > The custom itemrenderer simply takes the data from the overridden set
          > data()
          > method and displays it in a particular color depending on the data.
          >
          > I am using the Flex builder debugger to step through every step of the
          > way.
          > When the ItemEditEnd event handler finishes processing, the debugger tells
          > me
          > that the datasource has been correctly updated with the modifications to
          > the
          > value (in this case, to upper case) and the attribute added. Then the
          > debugger
          > steps through to the custom itemrenderer's set data() method, which has an
          > Object as an input parameter.
          >
          > I inspected that input parameter in the debugger and found that the entire
          > row
          > of the XML datasource is what that Object is. When I inspect that Object
          > further, I find that the attribute added exists, but that the value that
          > should
          > have been modified is not - but is instead the original value put into the
          > cell.
          >
          > 1. What could possibly be going on here?
          > 2. Should modifications to the value entered be updated in the datasource
          > when at the itemEditEnd event handler, or should they be done at the
          > overriden
          > set data() method of the itemrenderer?
          > 3. Would it be improper to get the instance of the custom renderer in the
          > itemEditEnd event handler and stuff the modified value into it (in this
          > case,
          > the .text attribute of the subclassed TextInput)? What is wrong with this
          > approach?

          Did you dispatch itemUpdated() on the collection?


          • 2. Re: DataProvider and itemEditEnd to the itemrenderer's set data()
            happybrowndog Level 1
            Thanks Amy,

            I tried itemUpdated() targetting the event.currentTarget.editedItemRenderer in the itemEditEnd event handler, and I also tried it targetting the datagrid itself. Both don't have the desired effect. Besides, the collection is already [Bindable], so is itemUpdated() even necessary?

            Curiously, in the example of "Example: Modifying data passed to or received from an item editor" at http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_8.html , it shows the itemRenderer being stuffed with a value in the itemEditEnd event handler. I thought that this was "against the framework" as trying to do similarly by setting the background color does not work right. What are your thoughts on this?
            • 3. Re: DataProvider and itemEditEnd to the itemrenderer's set data()
              Level 7

              "happybrowndog" <webforumsuser@macromedia.com> wrote in message
              news:ge5haj$8n$1@forums.macromedia.com...
              > Thanks Amy,
              >
              > I tried itemUpdated() targetting the
              > event.currentTarget.editedItemRenderer
              > in the itemEditEnd event handler, and I also tried it targetting the
              > datagrid
              > itself. Both don't have the desired effect. Besides, the collection is
              > already [Bindable], so is itemUpdated() even necessary?

              That doesn't make any sense. itemUpdated is a method of
              ListCollectionView...it doesn't "target" any kind of visual object.

              > Curiously, in the example of "Example: Modifying data passed to or
              > received
              > from an item editor" at
              > http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_8.html
              > , it
              > shows the itemRenderer being stuffed with a value in the itemEditEnd event
              > handler. I thought that this was "against the framework" as trying to do
              > similarly by setting the background color does not work right. What are
              > your
              > thoughts on this?

              No it doesn't. There isn't even an itemEditEnd handler _in_ that example.


              • 4. Re: DataProvider and itemEditEnd to the itemrenderer's set data()
                happybrowndog Level 1
                quote:

                Originally posted by: Newsgroup User

                "happybrowndog" <webforumsuser@macromedia.com> wrote in message
                news:ge5haj$8n$1@forums.macromedia.com...
                > Thanks Amy,
                >
                > I tried itemUpdated() targetting the
                > event.currentTarget.editedItemRenderer
                > in the itemEditEnd event handler, and I also tried it targetting the
                > datagrid
                > itself. Both don't have the desired effect. Besides, the collection is
                > already [Bindable], so is itemUpdated() even necessary?

                That doesn't make any sense. itemUpdated is a method of
                ListCollectionView...it doesn't "target" any kind of visual object.

                > Curiously, in the example of "Example: Modifying data passed to or
                > received
                > from an item editor" at
                > http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_8.html
                > , it
                > shows the itemRenderer being stuffed with a value in the itemEditEnd event
                > handler. I thought that this was "against the framework" as trying to do
                > similarly by setting the background color does not work right. What are
                > your
                > thoughts on this?

                No it doesn't. There isn't even an itemEditEnd handler _in_ that example.





                It's in the itemEditBegin event handler. Does it make a difference whether it is in the itemEditBegin or the itemEditEnd handler when I was talking about accessing the itemrenderer from the "outside"? I mean, it is deemed incorrect to, for example, setStyle() to do so, so why would setting the value of the .text property be any different?

                When you say "doesn't make sense.... doesn't target any kind of visual object" because the itemUpdated is a method of ListCollection, then I don't understand the usage of that method. The language reference states:
                """
                public function itemUpdated(item:Object, property:Object = null, oldValue:Object = null, newValue:Object = null):void
                Notifies the view that an item has been updated.
                """
                The "view" referred to above seems to be a visual object. Is the "item" parameter not the visual object? Please explain how to use this. I could not find any example online that makes it clear.
                • 5. Re: DataProvider and itemEditEnd to the itemrenderer's set data()
                  Level 7

                  "happybrowndog" <webforumsuser@macromedia.com> wrote in message
                  news:ge7k4a$sk$1@forums.macromedia.com...
                  >
                  quote:

                  Originally posted by: Newsgroup User
                  >
                  > "happybrowndog" <webforumsuser@macromedia.com> wrote in message
                  > news:ge5haj$8n$1@forums.macromedia.com...
                  > > Thanks Amy,
                  > >
                  > > I tried itemUpdated() targetting the
                  > > event.currentTarget.editedItemRenderer
                  > > in the itemEditEnd event handler, and I also tried it targetting the
                  > > datagrid
                  > > itself. Both don't have the desired effect. Besides, the collection is
                  > > already [Bindable], so is itemUpdated() even necessary?
                  >
                  > That doesn't make any sense. itemUpdated is a method of
                  > ListCollectionView...it doesn't "target" any kind of visual object.
                  >
                  > > Curiously, in the example of "Example: Modifying data passed to or
                  > > received
                  > > from an item editor" at
                  > > http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_8.html
                  > > , it
                  > > shows the itemRenderer being stuffed with a value in the itemEditEnd
                  > > event
                  > > handler. I thought that this was "against the framework" as trying to
                  > > do
                  > > similarly by setting the background color does not work right. What are
                  > > your
                  > > thoughts on this?
                  >
                  > No it doesn't. There isn't even an itemEditEnd handler _in_ that example.
                  >
                  >
                  >

                  >
                  > It's in the itemEditBegin event handler. Does it make a difference
                  > whether it
                  > is in the itemEditBegin or the itemEditEnd handler when I was talking
                  > about
                  > accessing the itemrenderer from the "outside"? I mean, it is deemed
                  > incorrect
                  > to, for example, setStyle() to do so, so why would setting the value of
                  > the
                  > .text property be any different?

                  Note that the itemEditBegin event handler actually CREATED the itemRenderer
                  it is working with. If it _didn't_ set the data, the itemRenderer wouldn't
                  know what to render. Also notice that the event is not trying to locate
                  some unrelated itemRenderer. Instead, it is using the editedItemRenderer
                  property of the dataGrid to locate the particular itemRenderer that the
                  dataGrid has chosen to make available to the world at large (and for very
                  good reason).

                  The engineers aren't perfect, but they're a good deal more experienced than
                  most of us. 99.7% of the time, if they have chosen to hide something, it is
                  because it is better practice for it to be hidden, and if they have chosen
                  to expose something, it is because they know that developers will need to
                  access it.

                  > When you say "doesn't make sense.... doesn't target any kind of visual
                  > object"
                  > because the itemUpdated is a method of ListCollection, then I don't
                  > understand
                  > the usage of that method. The language reference states:
                  > """
                  > public function itemUpdated(item:Object, property:Object = null,
                  > oldValue:Object = null, newValue:Object = null):void
                  > Notifies the view that an item has been updated.
                  > """
                  > The "view" referred to above seems to be a visual object. Is the "item"
                  > parameter not the visual object? Please explain how to use this. I could
                  > not
                  > find any example online that makes it clear.

                  yourXMLListCollection.itemUpdated(myDataGrid.editedItemRenderer.data);

                  HTH;

                  Amy