分享

SAP前端——使用SAPUI5来创建Web应用UI

 一骑当千_30 2018-05-15

前言

对于SAP产品开发而言,功能需求的实现当之无愧, 但是前端UI展示一直被吐槽,不够友好的界面,较为繁琐的操作流程,给用户增添了很多学习和使用上的烦恼。

但是自从SAPUI5诞生以来,移动显示,多元化的页面,不仅美观,更加实用便捷,下面我们来看看如何简单创建一个SAPUI5的应用。

首页创建

首先一个web应用程序,需要一个入口文件index.html:

<!DOCTYPE HTML> <html> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/> <script src='resources/sap-ui-core.js' id='sap-ui-bootstrap' data-sap-ui-libs='sap.m' data-sap-ui-theme='sap_bluecrystal'> </script> <!-- only load the mobile lib 'sap.m' and the 'sap_bluecrystal' theme --> <script> sap.ui.localResources('helloworld'); var app = new sap.m.App({initialPage:'idHelloWorld1'}); var page = sap.ui.view({id:'idHelloWorld1', viewName:'helloworld.HelloWorld', type:sap.ui.core.mvc.ViewType.XML}); app.addPage(page); app.placeAt('content'); </script> </head> <body class='sapUiBody' role='application'> <div id='content'></div> </body> </html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

编写View

view主要用于整体页面的布局展示,可以使用JS格式,XML格式,HTML格式,JSON格式,但是更为推荐大家使用XML格式语法。

<core:View xmlns:core='sap.ui.core' xmlns:mvc='sap.ui.core.mvc' xmlns='sap.m' controllerName='helloworld.HelloWorld' xmlns:html='http://www./1999/xhtml'> <Page title='Title'> <content> <Label text='This is Hello World'></Label> </content> </Page> </core:View>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

编写Controller

对于MVC结构而言自然少不了控制器,下面我们编写一个controller.

sap.ui.controller('helloworld.HelloWorld', { /** * Called when a controller is instantiated and its View controls (if available) are already created. * Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization. * @memberOf helloworld.HelloWorld */ // onInit: function() { // // }, /** * Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered * (NOT before the first rendering! onInit() is used for that one!). * @memberOf helloworld.HelloWorld */ // onBeforeRendering: function() { // // }, /** * Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here. * This hook is the same one that SAPUI5 controls get after being rendered. * @memberOf helloworld.HelloWorld */ // onAfterRendering: function() { // // }, /** * Called when the Controller is destroyed. Use this one to free resources and finalize activities. * @memberOf helloworld.HelloWorld */ // onExit: function() { // // } });
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

运行

应用Eclipse插件,以来Java Web运行环境及服务,测试我们的应用:

这里写图片描述

这里写图片描述

SAPUI5中文系列视频教程首发!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章