Topic
  • 8 replies
  • Latest Post - ‏2013-02-07T10:19:09Z by SystemAdmin
SystemAdmin
SystemAdmin
7615 Posts

Pinned topic How to set the value of the 'binding' object in a Dojo function

‏2013-02-04T15:20:11Z |
Hi, in load() function of a coach view which can fire a boundary event , I have a function called dojo.connect(tree_obj, 'onClick', function(item, node, evt) . And after some operations I plan to set a value of configuration object (a string) of my coach view. However when I say the following ;

this.context.binding.set("value", selectedNodeID);
or
context.binding.set("value", selectedNodeID);

It does not allow me to set my binding object's value and it gets angry. I get the following error (checked in the debug mode of IE9) .

TypeError: Unable to get value of the property 'binding': object is null or undefined.

Is there any suggestions for this problem ?

Regards,
Updated on 2013-02-07T10:19:09Z at 2013-02-07T10:19:09Z by SystemAdmin
  • kolban
    kolban
    3316 Posts

    Re: How to set the value of the 'binding' object in a Dojo function

    ‏2013-02-04T15:29:00Z  
    The statement:

    
    this.context.binding.set(
    "value", some value);
    


    Is used to set the variable that is bound to the Coach View in the Coach Designer. One has to first check that there is indeed a variable bound. For example:

    
    
    
    if (this.context.binding != undefined) 
    { this.context.binding.set(
    "value", some value); 
    }
    


    In addition, one has to specify a value that is the exact same type as the variable that is bound. What is your data type of "selectedNodeID" and what is the data type of your binding variable?

    Neil
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: How to set the value of the 'binding' object in a Dojo function

    ‏2013-02-05T07:53:01Z  
    • kolban
    • ‏2013-02-04T15:29:00Z
    The statement:

    <pre class="jive-pre"> this.context.binding.set( "value", some value); </pre>

    Is used to set the variable that is bound to the Coach View in the Coach Designer. One has to first check that there is indeed a variable bound. For example:

    <pre class="jive-pre"> if (this.context.binding != undefined) { this.context.binding.set( "value", some value); } </pre>

    In addition, one has to specify a value that is the exact same type as the variable that is bound. What is your data type of "selectedNodeID" and what is the data type of your binding variable?

    Neil
    Hi Neil ,
    Yes, I have a business data called selectedNode (string) in the coach view. And this data is bound to a variable in my coach.
    selectedNode(String) in coach view <-> selectedNode(String) in Coach.
    Here is the function I have ;
    dojo.connect(tree_obj, 'onClick', function(item, node, evt){

    var selectedNode= ""+ dijit.byId("CheckboxTree").attr("selectedItem").id;

    if (this.context.binding != undefined)
    {
    this.context.binding.set("value", "PrintSelectedNodeID");
    }

    context.trigger(function() {
    console.log('selected node: ' + selectedNode);
    window.alert(selectedNode);
    //console.log('binding val : ' + this.context.binding.get("value"));

    });
    });

    Here is the thing Neil, if my statement this.context.binding.set("value","newValue" ); is out of my dojo.connect function , there is no problem at all meaning that I can re-set my bound object very well. However when it is inside of my dojo function, it is messed up. It cannot allow me to play with the bound object there. I put the statement you have suggested me to enter, but the rest of my code stopped working meaning that I could not see "window.alert(selectedNode)" working .

    Briefly, my purpose is to change a bound variable or a configuration option variable inside of the dojo.connect function.

    Thanks for your help,

    Serhat
  • kolban
    kolban
    3316 Posts

    Re: How to set the value of the 'binding' object in a Dojo function

    ‏2013-02-05T08:48:05Z  
    Hi Neil ,
    Yes, I have a business data called selectedNode (string) in the coach view. And this data is bound to a variable in my coach.
    selectedNode(String) in coach view <-> selectedNode(String) in Coach.
    Here is the function I have ;
    dojo.connect(tree_obj, 'onClick', function(item, node, evt){

    var selectedNode= ""+ dijit.byId("CheckboxTree").attr("selectedItem").id;

    if (this.context.binding != undefined)
    {
    this.context.binding.set("value", "PrintSelectedNodeID");
    }

    context.trigger(function() {
    console.log('selected node: ' + selectedNode);
    window.alert(selectedNode);
    //console.log('binding val : ' + this.context.binding.get("value"));

    });
    });

    Here is the thing Neil, if my statement this.context.binding.set("value","newValue" ); is out of my dojo.connect function , there is no problem at all meaning that I can re-set my bound object very well. However when it is inside of my dojo function, it is messed up. It cannot allow me to play with the bound object there. I put the statement you have suggested me to enter, but the rest of my code stopped working meaning that I could not see "window.alert(selectedNode)" working .

    Briefly, my purpose is to change a bound variable or a configuration option variable inside of the dojo.connect function.

    Thanks for your help,

    Serhat
    Serhat,
    Ah, the joys of JavaScript. When your connect function is called .. "this" is not what you think it is. And hence "this.context" is undefined.

    What you need is to code:

    
    dojo.connect(tree_obj, 
    "onClick", lang.hitch(this, function(item, node, evt) 
    { .... 
    }));
    


    What is "lang.hitch()"? Go have a study on JavaScript and Dojo. You will need to AMD define "dojo/_base/lang -> lang"

    See http://dojotoolkit.org/reference-guide/1.8/dojo/_base/lang.html

    Neil
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: How to set the value of the 'binding' object in a Dojo function

    ‏2013-02-05T09:53:55Z  
    • kolban
    • ‏2013-02-05T08:48:05Z
    Serhat,
    Ah, the joys of JavaScript. When your connect function is called .. "this" is not what you think it is. And hence "this.context" is undefined.

    What you need is to code:

    <pre class="jive-pre"> dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt) { .... })); </pre>

    What is "lang.hitch()"? Go have a study on JavaScript and Dojo. You will need to AMD define "dojo/_base/lang -> lang"

    See http://dojotoolkit.org/reference-guide/1.8/dojo/_base/lang.html

    Neil
    Hmm, I see why we need to use lang, Neil .
    But it still does not seem to understand "this" and work with the following code ;
    dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt){

    context.trigger(function() {

    console.log('secilen node: ' + secilenNode);
    window.alert(secilenNode);
    if (this.context.binding != undefined) {
    this.context.binding.set("value", "newValue");
    }
    });

    }));

    Error shown in the browser - > TypeError: Unable to get value of the property 'binding': object is null or undefined .
    But I will try more:) thanks.
  • kolban
    kolban
    3316 Posts

    Re: How to set the value of the 'binding' object in a Dojo function

    ‏2013-02-05T14:15:55Z  
    Hmm, I see why we need to use lang, Neil .
    But it still does not seem to understand "this" and work with the following code ;
    dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt){

    context.trigger(function() {

    console.log('secilen node: ' + secilenNode);
    window.alert(secilenNode);
    if (this.context.binding != undefined) {
    this.context.binding.set("value", "newValue");
    }
    });

    }));

    Error shown in the browser - > TypeError: Unable to get value of the property 'binding': object is null or undefined .
    But I will try more:) thanks.
    Its likely that you need a second hitch ...

    
    dojo.connect(tree_obj, 
    "onClick", lang.hitch(this, function(item, node, evt)
    { this.context.trigger(lang.hitch(this, function() 
    { console.log(
    'secilen node: ' + secilenNode); window.alert(secilenNode); 
    
    if (this.context.binding != undefined) 
    { this.context.binding.set(
    "value", 
    "newValue"); 
    } 
    })) 
    }));
    
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: How to set the value of the 'binding' object in a Dojo function

    ‏2013-02-05T16:49:19Z  
    • kolban
    • ‏2013-02-05T14:15:55Z
    Its likely that you need a second hitch ...

    <pre class="jive-pre"> dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt) { this.context.trigger(lang.hitch(this, function() { console.log( 'secilen node: ' + secilenNode); window.alert(secilenNode); if (this.context.binding != undefined) { this.context.binding.set( "value", "newValue"); } })) })); </pre>
    Now it gives such an error . May it be related to the browser ?

    Error : Next service item is not defined.
    I cannot even put the statement "this.context ...." just after the dojo.connect function.

    dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt){

    this.context.binding.set("value","try" );

    ...
    ...
    }));
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: How to set the value of the 'binding' object in a Dojo function

    ‏2013-02-07T10:19:05Z  
    • kolban
    • ‏2013-02-05T14:15:55Z
    Its likely that you need a second hitch ...

    <pre class="jive-pre"> dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt) { this.context.trigger(lang.hitch(this, function() { console.log( 'secilen node: ' + secilenNode); window.alert(secilenNode); if (this.context.binding != undefined) { this.context.binding.set( "value", "newValue"); } })) })); </pre>
    Hi again Neil , thanks to your support I made it finally. The following piece of code in load() function of my coach view let me pass a specific value to binding object and from that binding object to a private object of the human service.
    Just to recap what I was trying to do and how I achieved it , read the following;

    var JsObject (in JS) -> bindingObject (coachView) -> private object (human service)

    Let me visualize what I tried to do first ; my purpose was to create a treeView (I will share how I created it's structure in the forum soon) and when the user clicks a node, the id of that node would be taken.

    That's why I first use "dojo.connect" function for the purpose of being notified when a node is clicked. Ok we can give an alert on the JS part by just putting a window.alert("") inside of the dojo.connect but we should also notify the human service that a variable inside my coach view has changed. For this purpose I also specified that my coach view that generated the tree structure can fire a boundary event so that I would be able to understand when it happens. But it is not finished yet, we should also use the method "this.context.trigger(function() {});" in order to make the fire operation complete.
    My problem was that I was not able to set a value of the binding object inside a dojo function since I was not able to use "this.context.options ..." because when I put "this" statement there, it was understood that "this" is the dojo.function itself. That's why it was giving a null error.
    Thanks to Neil, I used lang.hitch(... to be able to use "this". And here it goes like that ;
    dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt){
    document.getElementById('textA').value = "";
    selectedItems.push(tree_obj.getLabel(item));
    var len = selectedItems.length;

    document.getElementById('textA').value = "Selected Node is " + dijit.byId("CheckboxTree").attr("selectedItem").id;

    var selectedNode= ""+dijit.byId("CheckboxTree").attr("selectedItem").id;

    this.context.binding.set("value",selectedNode);

    this.context.trigger(function() {});
    // To publish another event to allow a popup to show up.
    var eventName = "DosyaPlaniPopup";
    var eventValue = "DosyaPlaniPopupValue";

    var message = {
    "eventName": eventName,
    "eventValue": eventValue
    };
    connect.publish(message.eventName, message);
    //
    }));
    Regards ,

    Serhat
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: How to set the value of the 'binding' object in a Dojo function

    ‏2013-02-07T10:19:09Z  
    • kolban
    • ‏2013-02-05T14:15:55Z
    Its likely that you need a second hitch ...

    <pre class="jive-pre"> dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt) { this.context.trigger(lang.hitch(this, function() { console.log( 'secilen node: ' + secilenNode); window.alert(secilenNode); if (this.context.binding != undefined) { this.context.binding.set( "value", "newValue"); } })) })); </pre>
    Hi again Neil , thanks to your support I made it finally. The following piece of code in load() function of my coach view let me pass a specific value to binding object and from that binding object to a private object of the human service.
    Just to recap what I was trying to do and how I achieved it , read the following;

    var JsObject (in JS) -> bindingObject (coachView) -> private object (human service)

    Let me visualize what I tried to do first ; my purpose was to create a treeView (I will share how I created it's structure in the forum soon) and when the user clicks a node, the id of that node would be taken.

    That's why I first use "dojo.connect" function for the purpose of being notified when a node is clicked. Ok we can give an alert on the JS part by just putting a window.alert("") inside of the dojo.connect but we should also notify the human service that a variable inside my coach view has changed. For this purpose I also specified that my coach view that generated the tree structure can fire a boundary event so that I would be able to understand when it happens. But it is not finished yet, we should also use the method "this.context.trigger(function() {});" in order to make the fire operation complete.
    My problem was that I was not able to set a value of the binding object inside a dojo function since I was not able to use "this.context.options ..." because when I put "this" statement there, it was understood that "this" is the dojo.function itself. That's why it was giving a null error.
    Thanks to Neil, I used lang.hitch(... to be able to use "this". And here it goes like that ;
    dojo.connect(tree_obj, "onClick", lang.hitch(this, function(item, node, evt){
    document.getElementById('textA').value = "";
    selectedItems.push(tree_obj.getLabel(item));
    var len = selectedItems.length;

    document.getElementById('textA').value = "Selected Node is " + dijit.byId("CheckboxTree").attr("selectedItem").id;

    var selectedNode= ""+dijit.byId("CheckboxTree").attr("selectedItem").id;

    this.context.binding.set("value",selectedNode);

    this.context.trigger(function() {});
    // To publish another event to allow a popup to show up.
    var eventName = "DosyaPlaniPopup";
    var eventValue = "DosyaPlaniPopupValue";

    var message = {
    "eventName": eventName,
    "eventValue": eventValue
    };
    connect.publish(message.eventName, message);
    //
    }));
    Regards ,

    Serhat