Search code examples
sapui5

Error: "Cannot add direct child without default aggregation defined for control XYZ"


I tried to find a solution by checking other questions with a similar error but none could help me. I tried to run the Component.js from my app in sandbox. Running the index.html works fine. My starting view is this:

<mvc:View
  xmlns="sap.m"
  xmlns:mvc="sap.ui.core.mvc"
  controllerName="com.sap.build.standard.qrCodeScanner.controller.Home"
>
  <Page id="home"
    class="customHomeBackground"
    showHeader="true"
    title="Home"
    showFooter="true"
  >
    <content>
      <FlexBox
        class="customFlexBoxHome"
        justifyContent="Center"
        alignItems="Center"
        wrap="Wrap"
      >
        <GenericTile class="customTile"
          header="Scan invitations"
          subheader="from your customers"
          frameType="OneByOne"
          press="_onGenericTilePress1"
        >
          <TileContent>
            <ImageContent src="sap-icon://bar-code"/>
          </TileContent>
        </GenericTile>
      </FlexBox>
    </content>
    <footer/>
    <headerContent/>
    <subHeader/>
    <customHeader/>
  </Page>
</mvc:View>

It's simply a single GenericTile. I can't access this view because of

Error: Cannot add direct child without default aggregation defined for control sap.m.GenericTile

console error

Accessing the other views is no problem. So when I add e.g. a button instead of the GernericTile + children, it works fine.

I also tried to add one of these sample tiles instead but same error. What's the problem with the GenericTile?


Solution

  • Piggybacking on @sunil-b-n's answer:

    In the current version of UI5 the example code works fine, as per the plunkr Sunil provided.

    However, if you change the library version to 1.38.15 like this, it is broken as per OP's question.

    Look at the difference. In the latest version, this code is valid:

    <GenericTile>
        <TileContent>
            <ImageContent src=""/>
        </TileContent>
    </GenericTile>
    

    But in old versions, named aggregations need to be explicitly added accordingly:

    <GenericTile>
        <tileContent> <!-- named aggregation required. Default since 1.46.x -->
            <TileContent>
                <content> <!-- named aggregation required. Default since 1.38.18 -->
                    <ImageContent src=""/>
                </content>
            </TileContent>
        </tileContent>
    </GenericTile>
    

    You need to figure out what version of UI5 you're on and use the appropriate SDK documentation to build your app, otherwise you'll run into trouble.

    You can view the version-specific Demo Kit by adding the version number to the URL, e.g. https://ui5.sap.com/1.38.8/