File Names and Locations (View and Controller)

In OpenUI5, controllers and views are defined and instantiated via a name that equals a OpenUI5 module name within the require/declare concept.

By default, all files have to be located in a subfolder of the resources folder of the Web application. If this location is not appropriate, deviations can be configured as described in the following example:

The following example assumes that your views and controllers are located on your local machine where the OpenUI5 runtime is loaded from another machine. When you instantiate a view or a controller, OpenUI5 runtime loads them in relation to the resources folder of the machine where OpenUI5 runtime was loaded. To inform OpenUI5 runtime that your views and controllers are located on your local machine, use the following code:

#!js
jQuery.sap.registerModulePath(sModuleNamePrefix, sURL);

or

#!js
sap.ui.localResources(sModuleNamePrefix);

It is usually sufficient to use sap.ui.localResources which internally registers sModuleNamePrefix to the URL "./" + sTransformedModuleNamePrefix, where all dots are replaced by slashes in the transformed name. All files starting with sModuleNamePrefix will then be loaded in relation to the location of the HTML page that called sap.ui.localResources.

If your files are located at http://<localhost:8080>/<myapp>/, for example, you can use registerModulePath as follows:

#!js
jQuery.sap.registerModulePath("myapp", "http://<localhost:8080>/<myapp>/");

or

#!js
sap.ui.localResources("myapp");

All views and controllers with a name starting with myapp, for example myapp.MyView, will then be loaded from your local machine.