openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

Enhancement Request: Being able to add XMLComposite to explicitly typed aggregations

Open boghyon opened this issue 7 years ago • 8 comments

Motivation

Several controls await specific type in their aggregation instead of just sap.ui.core.Control. E.g.:

  • Page's custom header/ footer awaiting controls of type sap.m.IBar
  • ListBase awaiting controls of type sap.m.ListItemBase
  • (and more..)

Problem

In the latter case, sap.m.CustomListItem is an often used control to have a customized layout consisting of any desired controls. To encapsulate the customized list item, there are mainly two options:

  1. Using as a fragment

    <items>
      <core:Fragment fragmentName="my.CustomListItem" type="XML" />
    </items>
    
    <!-- Fragment definition of my.CustomListItem -->
    <CustomListItem xmlns="sap.m">
      <SomeContainer property="{model>/property}">
        <!-- ... -->
      </SomeContainer>
    </CustomListItem>
    

    Drawbacks

    • Binding infos are already defined in the fragment definition. One cannot use the same fragment in a different context with different bindings declaratively.
    • Fragment is designed to be view context aware (unless it's a control in the static area) encouraging tight coupling with a specific view or application.
    • Behaviors aren't meant to be encapsulated either.

    So it's not really encapsulating.

  2. Creating a custom composite control by extending ListItemBase or CustomListItem

    Drawbacks

    Compared to the first approach where we could assemble controls declaratively, it's more complex and error-prone.

    ui5con-2018-news-from-control-development-5-1024

    Source: UI5con 2018: News from Control Development by @akudev

This leads to the (currently experimental) XMLComposite approach.

What is the expected result?

The extended XMLComposite control, which has CustomListItem as the only root control (see fragment definition above), can be added to the <items> aggregation of the ListBase control.

<List xmlns:custom="my.custom">
  <custom:MyCustomListItem ... />
</List>

What happens instead?

I'm not allowed to add <custom:MyCustomListItem> since it's not of type sap.m.ListItemBase, even though the top control is CustomListItem which is extended from ListItemBase.

After all, XMLComposite borrows the idea of Fragment. And fragments don't have their own representation in DOM. Following this concept, it would be nice if <custom:MyCustomListItem> is treated as <CustomListItem>.

Any other information?

Same issue: https://answers.sap.com/questions/754215/composite-control-xmlcomposite-for-a-listitem.html

boghyon avatar Feb 18 '19 13:02 boghyon

Hello @boghyon ,

Thank you for share your enhancement proposal. I've created an internal incident 1970160712. The status of the issue will be updated here in GitHub.

Regards, Niya

niyap avatar Feb 19 '19 09:02 niyap

Hi Nya,

I do not get your point here. What is this in relation with the XMLComposite? How did you define a composite?

You can define a composite like this:

sap.ui.define([ 'jquery.sap.global', 'sap/ui/core/XMLComposite' ], function (jQuery, XMLComposite) { "use strict"; return XMLComposite.extend("composites.List", { metadata: { aggregations: { items: { type: "sap.ui.core.Control", multiple: true } } } }); }, /* bExport= */true);

Now in the representation you would have to look....

<--- Here the control should get in

The problem in the presenation is that you would have to take care what control there is.

Silkinator avatar Feb 19 '19 11:02 Silkinator

I think the problem is with (the missing) multiple inheritance. Typed aggregations only allow instances of the specified type or subclasses thereof. If the type is an interface, implementations of that interface are expected.

But XMLComposite is a base class by itself. It is not a feature or mixing that can be used to implement a subclass of another control class. Therefore, it is not possible to implement an XMLComposite that fits into a typed aggregation with a non-interface-type (interface types shouldn't be a problem).

Fragments solve this problem by "disappearing at runtime". Only the type of their root content has to match the enclosing aggregation.

codeworrior avatar Feb 19 '19 11:02 codeworrior

My deep feeling is that perhaps this can only be solved with preprocessing. As you can not predefine a view without at least fixinging some attibutes ... what could be possible is just defining a property of type "object[]" and fix on its attributes so that they can then be used link this:

<List items="{$this>items}">

Silkinator avatar Feb 19 '19 11:02 Silkinator

Welp, I guess this can be closed now. XMLComposite is deprecated according to https://github.com/SAP/openui5/commit/25ae0f1a4e8d9da209ff7241e05f87c60b58b885.

boghyon avatar Mar 02 '21 14:03 boghyon

I think it's really unfortunate that the XMLComposite has been deprecated. Is there an official alternative we can be used instead?

mzimnn avatar Mar 05 '21 10:03 mzimnn

Closing since there is no response.

boghyon avatar Mar 12 '21 17:03 boghyon

I think it's really unfortunate that the XMLComposite has been deprecated. Is there an official alternative we can be used instead?

For completeness: The standard composite control should be used instead of the XMLComposite control. See SAP Answer

HeneryHawk avatar May 03 '21 11:05 HeneryHawk