Skip to Content
0
Dec 18, 2018 at 09:29 AM

How to assign to a Fragment a controller?

2270 Views

Hi all

I have the following view, that contains a fragment:

<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:smartFilterBar="sap.ui.comp.smartfilterbar"
    controllerName="ch.mindustrie.ZMM_OBJECTS_CLASSES.controller.ClassSelection" xmlns:html="http://www.w3.org/1999/xhtml">
    <smartFilterBar:SmartFilterBar id="SelectionFilterBar" entitySet="ZMM_C_CLASSIFICATION" search="onSearchClass">
        <smartFilterBar:controlConfiguration>
            <smartFilterBar:ControlConfiguration key="ClassType" preventInitialDataFetchInValueHelpDialog="false"></smartFilterBar:ControlConfiguration>
            <smartFilterBar:ControlConfiguration key="ClassNum" preventInitialDataFetchInValueHelpDialog="false"></smartFilterBar:ControlConfiguration>
        </smartFilterBar:controlConfiguration>
    </smartFilterBar:SmartFilterBar>
    <core:Fragment fragmentName="ch.mindustrie.ZMM_OBJECTS_CLASSES.fragment.Tree" id="TreeFm" type="XML"/>
</mvc:View>  

Then, I want to assign to the fragment a controller:

sap.ui.define([
    "ch/mindustrie/ZMM_OBJECTS_CLASSES/controller/BaseController",
    "ch/mindustrie/ZMM_OBJECTS_CLASSES/helper/Message",
    "ch/mindustrie/ZMM_OBJECTS_CLASSES/controller/TreeFragment.controller"
], function (BaseController, Message, TreeController) {
    "use strict";

    return BaseController.extend("ch.mindustrie.ZMM_OBJECTS_CLASSES.controller.ClassSelection", {
        onInit: function () {

        },

        onSearchClass: function () {
            const aFilter = this.byId("SelectionFilterBar").getFilters();
        },
    });
});   

The TreeController controller should be assigned to the fragment with the id TreeFm from above. How can I assign a controller to the fragment?

I considered the function sap.ui.core.Fragment.load, but I think it is not suitable for my case.