8 Replies Latest reply: Oct 19, 2011 11:12 AM by RituKnowsFlex RSS

    Using the customFields in the user descriptor within an item renderer

    RituKnowsFlex

      Hello,

       

      I am trying to use the customFields in the user descriptor as additional data to be bound to a component in an item renderer. I have some data that is tied to every user in the roster and I would like it to be displayed and modified at runtime based on user interaction. Here is the code I wrote for setting the customFields.

       

      protected function eGamingSession_creationCompleteHandler(event:FlexEvent):void

                                    {

                         // TODO Auto-generated method stub

                         for(var i:int=0;i<eGamingSession.userManager.userCollection.length;i++)

                                              {

                                                        eGamingSession.userManager.userCollection.getItemAt(i).customFie lds['score'] = 10;

       

                                                        trace("Value of stepper is: "+eGamingSession.userManager.userCollection.getItemAt(i).customFields.score);

                          }

       

                                    }

       

      Then in the item renderer, the code is as follows:

       

      <s:List id="userList"

                                                                            dataProvider="{eGamingSession.userManager.userCollecti on}"

                                                                            labelField="displayName"

                                                                            width="100%" height="100%">

       

                                                                  <s:itemRenderer>

                                                                            <fx:Component>

                                                                                      <s:ItemRenderer>

                                                                                                <fx:Script>

                                                                                                          <![CDATA[

                                                                                                                    import mx.events.FlexEvent;

       

                                                                                                                              // TODO Auto-generated method stub

       

                                                                                                                    override public function set data(value:Object):void {

                                                                                                                              super.data = value;

       

                                                                                                                              // Check to see if the data property is null.

                                                                                                                              if (value== null)

                                                                                                                                        return;

                                                                                                                              // If the data property is not null, 

                                                                                                                              // set the CheckBox control appropriately..

                                                                                                                              if (value.customFields.score == 10) {

                                                                                                                                        userStepper.value = 10;

                                                                                                                              }

                                                                                                                              else {

                                                                                                                                        userStepper.value = 0;

                                                                                                                              }

                                                                                                                    }

       

                                                                                                          ]]>

                                                                                                </fx:Script>

       

                                                                                                <s:HGroup width="100%">

       

                                                                                                          <s:Label text="{data.displayName}" paddingTop="5" width="60%"/>

       

                                                                                                          <s:NumericStepper id="userStepper" width="10%" value="{data.customFields['score']}"/>

       

                                                                                                </s:HGroup>

       

                                                                                      </s:ItemRenderer>

                                                                            </fx:Component>

                                                                  </s:itemRenderer>

                                                        </s:List>

       

       

      The problem is I don't see the customFields property set in the item renderer. I see it in the creationCompleteHandler, but it is not passed to the item renderer. Is the customFields not intended to be used this way?

       

      Will appreciate any insight,

      Thanks!

        • 1. Re: Using the customFields in the user descriptor within an item renderer
          Nigel Pegg Community Member

          Hi there,

           

          In order to set a custom user field, you have to round-trip it through the service - the line you've got in the creationComplete handler won't be enough. In general, the "descriptor" classes are meant to describe the state of the app, but can't be manipulated directly - you refer to the appropriate manager class' APIs to make changes (which will then be reflected in updates to the descriptors).

           

          In this case, the API you want is here : http://livedocs.adobe.com/labs/acrobatcom/com/adobe/rtc/sharedManagers/UserManager.html#se tCustomUserField()

           

          (Note that you have to set up your custom fields ahead of time by registering them at developer time - either use the Room Console for this, or use the registerCustomUserField method in userManager).

           

          hope that helps

            nigel

          • 2. Re: Using the customFields in the user descriptor within an item renderer
            RituKnowsFlex Community Member

            Hi Nigel,

             

            Thanks so much for your response. I tried your suggetions and I can see that the custom user filed is set right in the user collection when I use the setCustomUserField() method. I still don't see the value being synchronized across sessions though. I debugged it, and the user collection shows the customUserField with the right value, so not sure why it is not being bound correctly to the ui component. I also changed the event handler to the synchronizationChange instead of applicationComplete. Any insights?

             

            Thanks,

            Ritu..

             

            Here is the code for setting the field.

             

            protected function eGamingSession_synchronizationChangeHandler(event:SessionEvent):void

                                          {

                                                    // TODO Auto-generated method stub

                                                    if(eGamingSession.isSynchronized)

                                                    {

             

                                                              rosterItem.score = 1;

             

                                                              for(var i:int=0;i<eGamingSession.userManager.userCollection.length;i++)

                                                              {

                                                                        eGamingSession.userManager.registerCustomUserField("score") ;

                                                                        eGamingSession.userManager.setCustomUserField(eGamingSessio n.userManager.userCollection.getItemAt(i).userID,"score",rosterItem.score);

             

                                                                        trace("Value of stepper is: "+eGamingSession.userManager.userCollection.getItemAt(i).customFields.score);

             

                                    }

              }

            }

             

             

            Here is the code to display the value of custom user field.

             

            <s:List id="userList"

                                                                                  dataProvider="{eGamingSession.userManager.userCollecti on}"

                                                                                  labelField="displayName"

                                                                                  width="100%" height="100%">

             

                                                                        <s:itemRenderer>

                                                                                  <fx:Component>

                                                                                            <s:ItemRenderer>

             

                                                                                                      <s:HGroup width="100%">

             

                                                                                                                <s:Label text="{data.displayName}" paddingTop="5" width="60%"/>

                                                                                                                <s:Button id="winnerButton"

                                                                                                                                      width="30%"

                                                                                                                                      label="Winner!"

                                                                                                                                      visible="{!data.customFields.batonHolder}"/>

                                                                                                                <s:NumericStepper id="userStepper" width="10%" value="{data.customFields.score}"/>

             

                                                                                                      </s:HGroup>

             

                                                                                            </s:ItemRenderer>

                                                                                  </fx:Component>

                                                                        </s:itemRenderer>

              </s:List>

            • 3. Re: Using the customFields in the user descriptor within an item renderer
              Nigel Pegg Community Member

              Hi Ritu,

               

              My guess in this case is that the data binding you're doing in the stepper doesn't work with objects 2-levels deep (data.customFields.score). Could you add an eventlistener to userManager for UserEvent.CUSTOM_FIELD_CHANGE, and see if your changes are actually being round-tripped to the service? What evidence do you have that the userCollection is being updated? I don't see anything in the code above (the trace there happens too soon to tell).

               

              If your changes are generating events, the next thing I'd check is to see whether this is causing your itemRenderer's set data function to be triggered. If that's the case, then at least you could manually assign the value to the numeric stepper.

               

                hope that helps

                 nigel

              • 4. Re: Using the customFields in the user descriptor within an item renderer
                RituKnowsFlex Community Member

                Hi Nigel,

                I tested the code with the CUSTOM_FIELD_CHANGE event listener, and you are right. The stepper value is not being round-tripped to the server at runtime. So, our option is to maybe dispatch a custom event with the stepper value from within the item renderer, and update the user collection that way. But that is complex to teach in class, and we are wondering if you could suggest any other way to tie the score to the user collection. If not, we might drop this feature from the application for ease of explanation and teaching in class.

                Thanks,

                Ritu..

                • 5. Re: Using the customFields in the user descriptor within an item renderer
                  Nigel Pegg Community Member

                  Hi Ritu,

                   

                  So, you're saying you don't see a custom field change handler get fired? If that's the case, it's the code that's calling setCustomUserField which isn't working. Are you running this application with developer credentials? If you step into that code, do you see it succeeding in doing anything in the LCCS codebase?

                   

                    nigel

                  • 6. Re: Using the customFields in the user descriptor within an item renderer
                    RituKnowsFlex Community Member

                    Hi Nigel,

                     

                    I don't see the custom field change handler fired when I change the numeric stepper value. I see it get fired once when the application loads. I am using developer credentials, I think. I am not logging in as guest, if that is what you are asking. Also, I do see other things being updated and stored in the LCCS codebase.

                    Will it be easier to show you the code and application in a connect session?

                     

                    Thanks for all your help,

                    Ritu..

                    • 7. Re: Using the customFields in the user descriptor within an item renderer
                      Nigel Pegg Community Member

                      Sorry, this is really confusing. You say you *are* seeing the event handler fire when you start up the app? And now, you're somehow causing the numeric stepper to trigger further setCustomUserField calls, but you're not seeing that fire events? How are you hooking up the stepper to the setCustom call? I don't see any code for that.

                       

                        nigel

                      • 8. Re: Using the customFields in the user descriptor within an item renderer
                        RituKnowsFlex Community Member

                        I am not hooking up the stepper to the setCustomUserField call as yet. The only way for me to be able to do that would be to dispatch the custom event from the item renderer with the current value of the stepper. We are hoping to avoid that approach if possible since that is an advanced Flex topic and our audience may not understand it.

                        I was responding to your question about the event handler being fired at all, and the only time it is being fired is when we start the app. So, the only place that the setCustomUserField  is being used is in the synchronizationChange handler code. I am also confused by your statement that the code for the setCustomUserField might not be working.

                        I apologize for the confusion.

                         

                        Thanks,

                        Ritu..