Search code examples
sapui5

How use Namespaces in sapui5?


Someone can help with namespaces in sapui5, please. how to use it how to use it, I'm working with eclipse IDE.

I'm following a tutorial, and use this namespace, as would be the namespace with the structure of my project.

       controllerName="sap.ui.demo.db.controllers.App"

the structure of my proyect is:
databinding(proyectname)

->webcontent(folder)
->controllers(folder)
app.controller.js

->databinding(folder)
data.controller.js
data.view.xml

index.html

I tried several ways and I have not been successful.


Solution

  • The namespaces are set in index.html while bootstrapping. The property used to set is : data-sap-ui-resourceroots. For example :

    data-sap-ui-resourceroots='{
                "sap.ui.demo.cart" : "./"
            }'
    

    The above code sets the namespace and from now on 'sap.ui.demo.cart' will point to the folder where my index.html is present ( since I set the property to current folder (./) ). So for your case:

    data-sap-ui-resourceroots='{
                    "sap.ui.demo.db" : "./"
                }'
    

    Complete bootstrap :

    <script
            id='sap-ui-bootstrap'
            src='resources/sap-ui-core.js'
            data-sap-ui-theme='sap_bluecrystal'
            data-sap-ui-libs='sap.m'
            data-sap-ui-compatVersion="edge"
            data-sap-ui-resourceroots='{
                "sap.ui.demo.db" : "./"
            }' >
        </script>