on 04-13-2015 2:51 PM
I have a UIComponent which has a dependency of a faceless Component.
Main component metadata:
jQuery.sap.declare("MYAPP.Component");
sap.ui.core.UIComponent.extend("MYAPP.Component", {
metadata: {
dependencies: {
libs: [],
components: [
"MYAPP.Component2"
]
}, etc
The app indicates it has reached the faceless component, since if I make some deliberate syntax errors I do get the error messages when loading the webpage. I can also get a console.log("test") to print out from outside the sap.ui.core.Component.extend() code.
jQuery.sap.declare("Component2.Component");
console.log("outside test"); //this prints
sap.ui.core.Component.extend("Component2.Component", {
metadata: {
},
init: function(){
sap.ui.core.Component.prototype.init.apply(this, arguments);
console.log("component2 init test"); //this doesn't print
}
});
My folder structure:
MYAPP
/Component2 //faceless component folder
Component.js
/view //views and controllers folder
Component.js //main component
index.html
sap.ui.core.ComponentMetadata
// load the components
var aComponents = oDep.components;
if (aComponents) {
for (var i = 0, l = aComponents.length; i < l; i++) {
var sName = aComponents[i];
jQuery.sap.log.info("Component \"" + that.getName() + "\" is loading component: \"" + sName + ".Component\"");
sap.ui.component.load({
name: sName
});
}
}
sap.ui.component.load
Load a component without instantiating it.
so, that is an expected behavior, preloading but not instantiating, code should explicitly create it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your reply.
After some investigation, I added some code to the init function of my main component to instantiate the faceless component.
var oComponent = sap.ui.component({
name: "MYAPP.Component2",
id: "oCompId"
});
Interestingly, the override
sap.ui.core.UIComponent.prototype.init.apply(this, arguments);
caused an error which was fixed by removing that line.
Do you get any errors in the log?
I'm not sure why it doesn't enter the init() method, but could you try it outside the extended control, i.e.:
jQuery.sap.declare("Component2.Component");
sap.ui.core.Component.extend("Component2.Component", {
metadata: {
}
});
Component2.Component.prototype.init = function(){
sap.ui.core.Component.prototype.init.apply(this, arguments);
console.log("component2 init test"); //this doesn't print
};
and see if that works?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately this doesn't work either, I tried that and other variations and still nothing. The "outside test" log does print first before the main component which is good since I want the faceless component to run before the main one, but its lifecycle hooks just don't want to execute. There are also no log errors.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.