//Use promise to make sure the metadata loaded properly
this.getOwnerComponent().getModel().metadataLoaded().then(function() {
// Fetch OData model from the component
var oDataModel = this.getOwnerComponent().getModel();
// Fetching MetaModel from the OData model
var oMetaModel = oDataModel.getMetaModel();
});
oMetaModel.getMetaContext("/Orders")
with: The <template: with> instruction can be used to change a variable's value or to add a variable with a new name.
<template:with path="meta>com.sap.vocabularies.UI.v1.Badge" var="badge">
<!-- ... -->
</template:with>
<!-- Example shows iterating of Identification annotations(vocabulary) -->
<template:repeat list="{meta>com.sap.vocabularies.UI.v1.Identification}" var="field">
<Label text="{path: 'field>Label', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
<Text text="{path: 'field>Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
</template:repeat>
<!-- Example shows iterating of Identification annotations(vocabulary) using startIndex and length -->
<template:repeat list="{path:'entityType>com.sap.vocabularies.UI.v1.Identification',startIndex:1,length:3}" var="field">
<!-- ... -->
</template:repeat>
<template:if test="{meta>ImageUrl}">
<template:then>
<m:Image src="{path: 'meta>ImageUrl', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
</template:then>
<template:elseif test="{meta>TypeImageUrl}">
<commons:Image src="{path: 'meta>TypeImageUrl', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
</template:elseif>
<template:else>
<commons:Text text="{path: 'meta>Title/Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
</template:else>
</template:if>
<Annotations Target="com.test.XMLTemplate.Order">
<Annotation Term="com.sap.vocabularies.UI.v1.FieldGroup" Qualifier="General">
<Record Type="com.sap.vocabularies.UI.v1.FieldGroupType">
<PropertyValue Property="Data">
<Collection>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="OrderId"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="Price"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="OrderDesc"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="SupplierDesc"/>
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="Label" String="General"/>
</Record>
</Annotation>
</Annotations>
<mvc:View controllerName="com.test.XMLTemplate.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m" xmlns:smartForm="sap.ui.comp.smartform" xmlns:smartField="sap.ui.comp.smartfield"
xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1">
<App id="idAppControl">
<pages>
<Page title="{i18n>title}">
<content>
<!--aliasing the annotation helper-->
<template:alias name=".AH" value="sap.ui.model.odata.AnnotationHelper">
<template:with path="meta>com.sap.vocabularies.UI.v1.FieldGroup#General" var="fieldGroup">
<template:if test="{meta>com.sap.vocabularies.UI.v1.FieldGroup#General}">
<smartForm:SmartForm>
<smartForm:layout>
<smartForm:Layout labelSpanXL="3" labelSpanL="3" labelSpanM="3" labelSpanS="12" emptySpanXL="0" emptySpanL="0" emptySpanM="0" emptySpanS="0"
columnsXL="1" columnsL="1" columnsM="1"></smartForm:Layout>
</smartForm:layout>
<smartForm:Group label="{path:'fieldGroup>Label',formatter:'.AH.format'}">
<template:with path="fieldGroup>Data" var="data">
<template:repeat list="{data>}">
<smartForm:GroupElement>
<smartField:SmartField value="{path:'data>Value',formatter:'.AH.simplePath'}"/>
</smartForm:GroupElement>
</template:repeat>
</template:with>
</smartForm:Group>
</smartForm:SmartForm>
</template:if>
</template:with>
</template:alias>
</content>
</Page>
</pages>
</App>
</mvc:View>
// Code is written in onAfterRendering of controller of view where you want to use this template as a fragment. Code describing using template as fragment
// Output of this particular code will be UI5 Fragment
this.getOwnerComponent().getModel().metadataLoaded().then(function() {
var oDataModel = this.getOwnerComponent().getModel();
var oView = this.getView(); // This is the view in which the content will be pushed
var oMetaModel = oDataModel.getMetaModel();
//The content of page is preprocessed by XML View templating
var oFragment = XMLTemplateProcessor.loadTemplate("com.test.Demo.templates.Page", "fragment");
oMetaModel.loaded().then(function() {
var oProcessedFragment = XMLPreprocessor.process(oFragment, {
caller: "XML-Fragment-templating"
}, {
bindingContexts: {
meta: oMetaModel.getMetaContext("/Orders")
},
models: {
meta: oMetaModel
}
});
oFragment = sap.ui.xmlfragment({
fragmentContent: oProcessedFragment
}, this);
oView.getAggregation("content")[0].addContent(oFragment);
this.bFirstTime = true;
}.bind(this));
}.bind(this));
// Code is written in component. Code describing Template as a view.
// Output of this particular code will be UI5 View
/* pass the metacontext and metamodel to the preprocessor */
oMetaModel.loaded().then(function () {
var oTemplateView = sap.ui.view({
preprocessors: {
xml: {
bindingContexts: {
meta: oMetaModel.getMetaContext(sPath)
},
models: {
meta: oMetaModel
}
}
},
type: sap.ui.core.mvc.ViewType.XML,
viewName: "com.test.XMLTemplate.view.View1"
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |