Question

I have a CustomDataGrid that extends from DataGrid and CustomDataGridColumn that extends from DataGridColumn.

CustomDataGridColumn has member variables of type Function.

Inside my view, I inject a presentation model using parsley.

The code is as follows:

<fx:Declarations> 
        <spicefactory:Configure/> 
    </fx:Declarations> 

<fx:Script> 

        [Inject(id="associatedDocumentsPM")] 
        [Bindable] 
        public var model:AssociatedDocumentsPM; 


</fx:Script> 

   <customDataGrid:CustomDataGrid id="AssocDocGrid" 
                                   width="100%" height="{(documentDataList.length+2)*20}" 
                                   doubleClickEnabled="true" enabled="{modeHandler.appEnable}" 
                                   dataP="{documentDataList}" 
                                   sortableColumns="false"> 
        <customDataGrid:columnList> 
            <customDataGrid:CustomDataGridColumn 
                textAlign="left" 
                dataFieldIdentifier="documentName" 
                headerText="Document Type" 
                modifyLabelField="{model.modifyLabelField}" 
                dataField="documentName" 
                isNaNZero="true" 
                showDataTips="true" 
                editable="false"/> 
                ...more columns here...  
       </customDataGrid:columnList>
    </customDataGrid:CustomDataGrid>

The AssociatedDocumentsPM has functions defined and these are set in the columns.

One example being for attribute modifyLabelField="{model.modifyLabelField}"

CustomDataGridColumn.myLabelField is of type Function. myLabelField inside AssociatedDocumentsPM is a public function.

The Parsley Context file is in the parent of the above file and declares the PM as follows:

AssocDocPMFactory is a class with a sole function decorated with [Factory].

So the problem is the following:

When I debug the application and check the columnList of the DataGrid, the variable modifyLabelField is null.

Are function bindings treated differently than variables? I'm using Flex 4.5.1 together with Parsley 2.4.1

I understand that injection could happen after creationComplete is invoked but I thought the binding would take care of that.

I have a feeling that the model - the PM - is null until much much later and the function binding is not triggered.

I tried to use FastInject as well but to no avail.

Is this a problem with function pointers and Flex binding?

Was it helpful?

Solution

No it isn't. If you have these kind of doubts, it's always a good idea to quickly set up a simple isolated test situation that verifies your assumption. I created the following to test yours:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               creationComplete="onCreationComplete()" >

    <fx:Script>
        <![CDATA[
            private function onCreationComplete():void {
                test = function(item:*):String {
                    return "AAA";
                }
            }

            [Bindable]
            private var test:Function;
        ]]>
    </fx:Script>

    <s:List labelFunction="{test}">
        <s:dataProvider>
            <s:ArrayList>
                <fx:String>A</fx:String>
                <fx:String>B</fx:String>
                <fx:String>C</fx:String>
            </s:ArrayList>
        </s:dataProvider>
    </s:List>

</s:Application>

If the test Function variable is declared Bindable, you'll see 3 times "AAA". If you remove the Bindable metadata, you'll see "A", "B", "C".

So clearly binding works with function pointers too (and you'll have to look elsewhere to find your nullpointer).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top