title: Shared event handler for XML views with different controllers
body: <p>Given two XML Views:</p>
  <pre><code>&lt;mvc:View
    controllerName=&quot;my.namespace.controller.First&quot;
    xmlns:mvc=&quot;sap.ui.core.mvc&quot; 
    xmlns=&quot;sap.m&quot;&gt;
  
    &lt;Button press=&quot;.onBtnPress&quot; /&gt;
  &lt;/mvc:View&gt;
  
  
  &lt;mvc:View
    controllerName=&quot;my.namespace.controller.Second&quot;
    xmlns:mvc=&quot;sap.ui.core.mvc&quot; 
    xmlns=&quot;sap.m&quot;&gt;
  
    &lt;Button press=&quot;.onBtnPress&quot; /&gt;
  &lt;/mvc:View&gt;
  </code></pre>
  <p>As expected, the press  event is handled by <code>First.controller.js</code> or <code>Second.controller.js</code>.</p>
  <p><strong>Instead of duplicating the event handler code or implementing handlers in each Controller to chain/hand off the work, I want to declare a shared event handler.</strong></p>
  <p>According to <a href="https://help.sap.com/saphelp_nw74/helpdata/en/b0/fb4de7364f4bcbb053a99aa645affe/content.htm" rel="nofollow noreferrer" title="documentation">docs</a> this should be possible, using a naming convention for the handler:</p>
  <blockquote>
  <p>Names starting with a dot ('.') are always assumed to represent a method in the controller.</p>
  <p>Names containing a dot at a later position are assumed to represent global functions and are resolved by calling jQuery.sap.getObject with the full name.</p>
  </blockquote>
  <p>So I change the handler and declare a shared object, like so:</p>
  <p><em>First.view.xml:</em></p>
  <pre><code>&lt;Button press=&quot;my.namespace.Shared.onBtnPress&quot; /&gt;
  </code></pre>
  <p><em>Shared.js:</em></p>
  <pre><code>jQuery.sap.declare(&quot;my.namespace.Shared&quot;);
  
    my.namespace.Shared = (function() {
  
      var onBtnPress = function() {
        console.log(&quot;button pressed&quot;);
      };
  
    return { onBtnPress : onBtnPress };
  }());
  </code></pre>
  <p>Warning logged (debug sources) during view initialisation:</p>
  <blockquote>
  <p>sap.ui.core.mvc.XMLView#__xmlview1: event handler function &quot;my.namespace.Shared.onBtnPress&quot; is not a function or does not exist in the controller. -</p>
  </blockquote>
  <p>Calling <code>jQuery.sap.getObject(&quot;my.namespace.Shared&quot;)</code> yields <code>undefined</code></p>
  <p>Same issue when using <code>sap.ui.define</code> to make the object known.</p>