Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse components in xml views

Tags:

sapui5

The developer-guide states "Components are independent and reusable parts used in SAPUI5 applications." but it does not give an example of how to reuse one component in another.

Specifically, I have a component which I want to reuse in different applications. This component has a backing OData-service and a view implementing the UI, and also a controller for encapsulated functions. I have no problems instantiating the component in the applications (which are of course components themselves), but I'm stuck with how I can include the compontent's view in the xml definition of the application. The developer-guide mentions a ComponentContainer as a wrapping control, but I have found no examples on how to use this.

Note that I do know how to reuse fragments or views, but my case seems different since my view is tightly bound to the OData-service (data-binding) of the component.

Any pointer to sample code is highly appriciated. Thanks.

like image 374
Bernhard Bablok Avatar asked Nov 16 '25 16:11

Bernhard Bablok


1 Answers

WIth SAPUI5 1.50+ some new feature were introduced allowing you to do the following (usages are declared in the manifest.json):

<core:ComponentContainer
    id="compOld"
    name="nabi.demo.comp.reuse.northwind.customer.selectionBtn"
    async="true"
    componentCreated="onComponentCreated"/>

<core:ComponentContainer
    id="compNew1"
    usage="simpleCustomerSelectionBtn1"
    async="true"
    componentCreated="onComponentCreated"/>

<core:ComponentContainer
    id="compNew2"
    usage="simpleCustomerSelectionBtn2"
    async="true"
    componentCreated="onComponentCreated"/>

For details see here: Implementing Re-use Components in SAPUI5 libraries and consuming them in SAPUI5 apps

like image 77
Nabi Avatar answered Nov 19 '25 08:11

Nabi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!