title: how to bind control to json model in sapui
body: <blockquote>
    <p>why can't i use these <code>sap.ui.getCore().setModel(oModel) and
    this.getView().setModel("oModel","someModel")</code>  in functions other
    than life cycle hooks of controller in sapui5.</p>
    
    <p>I am trying to bind model to the controls of my view without giving it
    an id. so i want to make a model and set that model to the view where
    i will bind.</p>
  </blockquote>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
          &lt;meta charset="UTF-8"&gt;
  
          &lt;title&gt;Handler Context in JavaScript Views&lt;/title&gt;
  
          &lt;script id="sap-ui-bootstrap" 
                  type="text/javascript"
                  src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js"
                  data-sap-ui-theme="sap_bluecrystal"
                  data-sap-ui-libs="sap.m"
                  data-sap-ui-xx-bindingSyntax="complex"
          &gt;
          &lt;/script&gt;
  
          &lt;script&gt;
              jQuery.sap.require("sap.m.MessageToast");
              sap.ui.jsview("local.view", {
                  getControllerName: function() {
                      return "local.controller";
                  },
                  createContent: function(oController) {                    
       var oText=new sap.m.Text();
       oText.bindProperty("text","oModel&gt;/myData");
       
       var oInput=new sap.m.Input();
       oInput.bindValue("oModel&gt;/myData");
       
       var oIn=new sap.m.Input();
       oIn.bindValue("oModel&gt;/myData");
       
       var oBar=new sap.m.Bar({contentLeft:oIn,contentMiddle:oText});
       var oButton=new sap.m.Button({text:"press to reset",
          press:function(){
           oController.resetModel();
          }
          });
       var oPage=new sap.m.Page({headerContent:[oInput],footer:oBar,showNavButton:true,content:[oButton]});
       var oShell=new sap.m.App({pages:oPage});
       return oShell;
                  }
              });
     
     
     
              sap.ui.controller("local.controller", {
      onInit:function(){
       var aData={"myData":"enter!!"};
       
       var oModel=new sap.ui.model.json.JSONModel();
       oModel.setData(aData);
       sap.ui.getCore().setModel(oModel,"oModel");
      },
      resetModel:function(){
       var oModel=sap.ui.getCore().getModel("oModel");
       oModel.oData.myData="Reset";    
      }
              });
              sap.ui.view({
                  type: sap.ui.core.mvc.ViewType.JS,
                  viewName: "local.view"
              }).placeAt("uiArea");
          &lt;/script&gt;
  
      &lt;/head&gt;
  
      &lt;body class="sapUiBody" role="application"&gt;
          &lt;div id="uiArea"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>how can i update my model which is bound to other controls on button press</p>
  
  <p>Is there any way to access controls in controller of my view without giving it an id?<br>
  Regards,
  Ajaay   </p>