Code Examples

Gain a quick impression how things are done with Ui5Strap.

MVC

This example shows how the MVC pattern is implemented with Ui5Strap.

  • myproject
  • www
  • apps
  • helloworld
  • controller
  • HelloWorld.controller.js
  • view
  • HelloWorld.view.xml
  • app.json
  • index.html

App configuration

The app configuration defines the basic structure of the app.

  helloworld/app.json
{
    "app" : {
        "id" : "mycompany.helloworld",
        "name" : "Hello World"
    },
	
    "rootNavigation" : {
        "module" : "pks.ui5strap.core.NavContainer",
        "initialPages" : [
            "pageHelloWorld"
        ]
    },
    
    "pages" : [
        {
            "id" : "pageHelloWorld",
            "viewName" : ".view.HelloWorld"
        }
    ]
}

Controller with event handler

The controller contains the event handlers and helper functions used in the view.

  helloworld/controller/HelloWorld.controller.js
/**
* Simple Controller.
*/
sap.ui.define(['pks/ui5strap/viewer/Controller'], function(Controller){
	
	"use strict";
	
	var controllerImpl = {
		onInit : function(){
			
		},
		
		onPressButton : function(oEvent){
			alert("Hello, world!");
		}
	};
	
	//Return constructor
	return Controller.extend("mycompany.helloworld.controller.HelloWorld", controllerImpl);

});

View with button

The view contains the declarative composition of controls.

  helloworld/controller/HelloWorld.view.xml
<!-- XML Root Node -->
<sapUiCoreMvc:View controllerName="mycompany.helloworld.controller.HelloWorld" xmlns="pks.ui5strap.bs3" xmlns:sapUiCoreMvc="sap.ui.core.mvc"
                      xmlns:data="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1">
    <!-- START Page Content -->

    <Container type="Website" class="myContainer">
        <!-- Button that triggers the controller event. -->
        <Button text="Say Hello" tap=".onPressButton" />
    </Container>
    
    <!-- END Page Content -->
</sapUiCoreMvc:View>

More information