UI5应用程序在作为组件调用时中断



所以,我有这个UI5应用程序,当通过index.html调用它时,它运行得很好,但当我试图将其作为组件调用时,它会中断(找不到资源、加载失败、404错误等)。两个应用程序(主叫和被叫)都在网关上

这是应用程序文件夹结构。calle_app-Struct.jpg

link to GitHub - https://github.com/mailsandip/component_test

所有视图都在zui5_trip_confirmation->views文件夹下。。图像和模型位于各自的文件夹中。

component.js位于文件夹component下,定义为

// define a new UIComponent  
jQuery.sap.declare("components.Component");  
jQuery.sap.require("sap.ui.core.UIComponent");  
jQuery.sap.require("sap.ui.commons.Button");  
jQuery.sap.require("sap.ui.table.Table");  
//new Component  
sap.ui.core.UIComponent.extend("components.Component", {  
metadata : {  
properties : {  
text: "string"  
}  
}  
});  
components.Component.prototype.createContent = function(){  
/* trying to register the path zui5_trip_confirmation where all the views are stored */  
sap.ui.localResources("zui5_trip_confirmation");  
// jQuery.sap.registerModulePath('zui5_trip_confirmation','/sap/bc/ui5_ui5/sap/zui5_trip_conf/zui5_trip_confirmation');  
this.oView = sap.ui.jsview("idHome", "zui5_trip_confirmation.views.Home");  
return this.oView;   
};  

调用方应用程序将其称为

jQuery.sap.registerModulePath('components','/sap/bc/ui5_ui5/sap/zui5_trip_conf/components');
var oComp1 = sap.ui.getCore().createComponent({
name: "components",
id: "Comp1",
settings: {text: "Hello World"}
});
var oCompCont1 = new sap.ui.core.ComponentContainer("CompCont1", {
component: oComp1
});
oCompCont1.placeAt("content");

当我运行调用方应用程序时,我会在控制台上得到未找到资源的错误。基本上,组件无法解析视图/模型/图像的路径。

这里可能出了什么问题?

问候Sandip

使用

jQuery.sap.registerModulePath('components','/sap/bc/ui5_ui5/sap/zui5_trip_conf/components')

您告诉核心查找"/sap/bc/[…]"中以"components"开头的所有内容。

然后您说组件名称是"components"。那不应该是"组件。组件"吗?

好,用示例更新:

(我希望这能让它更清楚)

最重要的部分:我们注册组件文件文件夹的路径,并为其分配前缀。在组件内部,我们启动每一个对象/元素/控件等。具有与组件相同的前缀。(在您的情况下:"zui5_conf_try")。

我在服务器上创建了示例:http://dev.himmelrath.net/ui5/so_componentExample/您可以在此处下载所有文件:http://dev.himmelrath.net/ui5/so_componentExample.zip

在组件的外部,当在index.html中创建ComponentContainer时,我们通过注册其前缀来注册所有组件部分的路径。

index.html:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="../resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-theme="sap_goldreflection">
</script>
<script>
// The following line tells the core to look for everything that starts with
// "zui5_conf_try." in the (relative to this html-file's URL) folder "zui5_conf_try"
// This should be equivalent to:
//     jQuery.sap.registerModulePath("zui5_conf_try", "./zui5_conf_try")
sap.ui.localResources("zui5_conf_try")
// Let's skip the component instantiation, ComponentContainer can do that for us
// when we gie it the name of our component.
var oCompCont1 = new sap.ui.core.ComponentContainer("CompCont1", {
name: "zui5_conf_try",
});
oCompCont1.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>

zui5_conf_try/Components.js:

// define a new UIComponent
jQuery.sap.declare("zui5_conf_try.Component");
//jQuery.sap.require("sap.ui.core.Core");
jQuery.sap.require("sap.ui.core.UIComponent");
jQuery.sap.require("sap.ui.commons.Button");
jQuery.sap.require("sap.ui.table.Table");
//new Component
sap.ui.core.UIComponent.extend('zui5_conf_try.Component',{  
metadata : {
version : "1.0",
},  
// DO NOT overwrite the components init method - it is used internally
// and calls the createContent-method
/*
init: function() {
alert('init222');       
},
*/
createContent: function() {
// Using sap.ui.localResources('views'); in this context would still 
// register the path relative to our index.html, not the Component.js
// so we do not use it. Instead we use the same prefix as the component
// for our views, because we know that that path must be set correctly
// if this file has been loaded.
// This should look for "./views/Home.view.js" relative to the components
// path, since the components path was registered in the index.html ouside
// the component
var view = sap.ui.jsview("idHome", "zui5_conf_try.views.Home");
return view;
}
});

zui5_conf_try/views/Home.view.js:

sap.ui.jsview("zui5_conf_try.views.Home", {  
getControllerName: function() {
return "zui5_conf_try.views.Home";     
},
createContent: function(oController) {
var oButton = new sap.ui.commons.Button({text:"I am zui5_conf_try.views.Home"});
oButton.attachPress(oController.handleButtonClicked);
return oButton;
}
});

zui5_conf_try/views/Home.controller.js:

sap.ui.controller("zui5_conf_try.views.Home", {
handleButtonClicked : function() {
alert("You just clicked the view button...");
}
});

好的,所以多看一点-看起来Component.js没有加载资源,尽管有一个明确的加载提到

--inside component.js ----
sap.ui.localResources('views');
sap.ui.resources('images');
var view = sap.ui.jsview("idHome", "views.Home");
return view;
---- exit ----

这就是让我困惑的地方,核心应该已经加载了关于Component.js位置的视图。图像文件夹也会出现同样的问题。

This seems like an issue with the Component framework.

问候Sandip

最新更新