Error “Cannot add direct child without default aggregation defined for control …”

二次信任 提交于 2020-02-25 13:27:08

问题


I am getting the error "Cannot add direct child without default aggregation defined for control sap.m.Label". Not sure what this means. Here is my fragment:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:f="sap.f">
    <ResponsivePopover id="popover" title="{Name}" class="sapUiPopupWithPadding" placement="Bottom">
        <beginButton>
            <Button id="submit" text="{i18n>submit}" press="onSubmit" class="sapUiTinyMargin"/>
        </beginButton>
        <content>
            <f:GridContainer>
                <f:layout>
                    <f:GridContainerSettings rowSize="5rem" columnSize="8rem" gap="1rem"/>
                </f:layout>
                <f:layoutS>
                    <f:GridContainerSettings rowSize="5rem" columnSize="10rem" gap="0.5rem"/>
                </f:layoutS>
                <f:layoutXS>
                    <f:GridContainerSettings rowSize="5rem" columnSize="10rem" gap="0.5rem"/>
                </f:layoutXS>
                <Label text="{i18n>req}" required="true">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="3"/>
                    </f:layoutData>
                </Label>
                <Label id="txt" text="{i18n>cat}" required="true">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="3"/>
                    </f:layoutData>
                </Label>
                <RadioButton id="rbtn1" text="{i18n>grq}">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="4"/>
                    </f:layoutData>
                </RadioButton>
                <RadioButton id="rbtn2" text="{i18n>frq}">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="4"/>
                    </f:layoutData>
                </RadioButton>
                <TextArea id="txtarea" value="" placeholder="{i18n>typeq}" growing="true" growingMaxLines="10" width="100%">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="7"/>
                    </f:layoutData>
                </TextArea>
                <Text text="{i18n>note}">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="7"/>
                    </f:layoutData>
                </Text>
            </f:GridContainer>
        </content>
    </ResponsivePopover>
</core:FragmentDefinition>

Expected result is the fragment will load with out errors.


回答1:


The issue is in <SapMControl><f:layoutData>. Remove the f: in <f:layoutData>.

sap.ui.require([
  "sap/ui/core/Core"
], Core => Core.attachInit(() => sap.ui.require([
  "sap/ui/core/Fragment"
], Fragment => Fragment.load({
  definition: `<f:GridContainer xmlns:f="sap.f" xmlns="sap.m">
    <Label text="Label within GridContainer">
      <layoutData>
        <f:GridContainerItemLayoutData columns="3"/>
      </layoutData>
    </Label>
  </f:GridContainer>`
}).then(control => control.placeAt("content")))));
<script id="sap-ui-bootstrap" src="https://ui5.sap.com/resources/sap-ui-core.js"
  data-sap-ui-libs="sap.m,sap.f,sap.ui.layout"
  data-sap-ui-theme="sap_fiori_3"
  data-sap-ui-async="true"
  data-sap-ui-compatversion="edge"
  data-sap-ui-xx-waitfortheme="init"
></script>
<body id="content" class="sapUiBody"></body>

The same applies to <RadioButton> and <TextArea> in your case.


"Cannot add direct child without default aggregation defined for control sap.m.Label". Not sure what this means.

Within control definition, control developers can assign a default aggregation so that application developers can add children without having to put an aggregation name explicitly in the XML view definition. An example of this is sap.f.GridContainer. Its default aggregation is items.src Hence, you won't need to add <f:items> to add children there (See my code snippet above).

If, however, the control has no default aggregation and the child node name matches with none of the named aggregations, the XML processor will throw the above error.

The named aggregation must have the same namespace as the parent --> <Label><layoutData>




回答2:


The sap.m.Label and the other controls cannot be used inside sap.f.Gridcontainer directly. You'll need to place them inside <f:items> first.

From the documentation: https://sapui5.netweaver.ondemand.com/sdk#/api/sap.f.GridContainer%23overview

<f:GridContainer>
  <f:layout>
    <f:GridContainerSettings rowSize="5rem" columnSize="5rem" gap="1rem" />
  </f:layout>
  <f:layoutS>
    <f:GridContainerSettings rowSize="4rem" columnSize="4rem" gap="0.5rem" />
  </f:layoutS>
  <f:items>
    <GenericTile header="Sales Fulfillment">
      <layoutData>
        <f:GridContainerItemLayoutData rows="2" columns="2" />
      </layoutData>
    </GenericTile>
    <w:Card manifest="url-to-manifest">
      <w:layoutData>
        <f:GridContainerItemLayoutData rows="6" columns="3" />
      </w:layoutData>
    </w:Card>
    <Panel>
      <layoutData>
        <f:GridContainerItemLayoutData columns="4" />
      </layoutData>
      <Text text="Sales information" />
    </Panel>
  </f:items>
</f:GridContainer>


来源:https://stackoverflow.com/questions/59654209/error-cannot-add-direct-child-without-default-aggregation-defined-for-control

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!