How to Access Elements from XML Fragment by ID
<p>I am working on a SAPUI5 application. I have an XML view which contains an XML <a href="https://openui5.hana.ondemand.com/#/api/sap.ui.core.Fragment" rel="noreferrer">Fragment</a> and a Button to save.</p>
<p>The fragment contains a few controls like drop-down, text field and a table.
When I press on the save button, I need to get all the rows in the table and call an OData update service.</p>
<p>The problem is in the <code>onSave</code> method in view controller. I get an error while accessing the table using its ID. Can anyone help me and advice how can I access controls used in fragments by their ID in the controller?</p>
<p>Here is the code snippet:</p>
<p>View:</p>
<pre class="lang-xml prettyprint-override"><code>&lt;mvc:View xmlns:mvc=&quot;sap.ui.core.mvc&quot; xmlns:core=&quot;sap.ui.core&quot; xmlns:form=&quot;sap.ui.layout.form&quot; xmlns=&quot;sap.m&quot;&gt;
    &lt;Page&gt;
        ...
        &lt;form:SimpleForm&gt;
            &lt;core:Fragment id =&quot;fr1&quot; fragmentName=&quot;first&quot; type=&quot;XML&quot; /&gt;
            &lt;Button id=&quot;id1&quot; press=&quot;onSave&quot; /&gt;
        &lt;/form:SimpleForm&gt;
    &lt;/Page&gt;
&lt;/mvc:View&gt;
</code></pre>
<p>Fragment definition:</p>
<pre class="lang-xml prettyprint-override"><code>&lt;core:FragmentDefinition xmlns=&quot;sap.m&quot; xmlns:core=&quot;sap.ui.core&quot;&gt;
    &lt;Table id=&quot;tab1&quot; mode=&quot;MultiSelect&quot;&gt;
        ...
    &lt;/Table&gt;
&lt;/core:FragmentDefinition&gt;
</code></pre>
<p>Controller:</p>
<pre class="lang-js prettyprint-override"><code>sap.ui.controller(&quot;view&quot;, {
    onSave: function() {
        //var tab = this.getView().byId(&quot;tab1&quot;); // Not working
        var tab  = sap.ui.getCore().byId(&quot;tab1&quot;); // Not working
    },
    // ...
});
</code></pre>