How to do element binding in xml fragment in UI5 application?

I’m developing a UI5 application.

I have the following odata entity:

<EntityType Name="order">
    <Key>
        <PropertyRef Name="id"/>
    </Key>
    <Property Name="id" Nullable="false" Type="Edm.Guid"/>
    <Property Name="creatorId" Type="Edm.Guid"/>
    <NavigationProperty FromRole="To_Order" Name="Creator" Relationship="bwm.UserOrder" ToRole="From_User"/>
</EntityType>
<EntityType Name="User">
    <Key>
        <PropertyRef Name="id"/>
    </Key>
    <Property Name="id" Nullable="false" Type="Edm.Guid"/>
    <Property Name="name" Type="Edm.String"/>
    <Property Name="phone" Type="Edm.String"/>
    <Property Name="avatar" Type="Edm.String"/>
    <NavigationProperty FromRole="From_User" Name="OrderSet" Relationship="bwm.UserOrder" ToRole="To_Order"/>
</EntityType>

I’ve simplified the entity model. Basically there’s the Order and User entity, on Order entity, there’s a navigation property Creator which reference to User entity.

I want to define a fragment which displays user information, I want to bind the UI elements relatively to a user :

<HBox  xmlns="sap.m">
    <items>
        <Image src="{avatar}"/>
        <VBox>
            <items>
                <Label text="{name}"/>
                <Label text="{phone}"/>
            </items>
        </VBox>
    </items>
</HBox>

Now I have the page which is displaying a list of Orders, but I don’t know how to element binding the fragment to the Creator navigation property:

<GrowingList threshold="10"
            items="{
                path: '/OrderSet'
            }">
    <items>
        <CustomListItem >
            <content>
                <core:Fragment fragmentName="xxx.fragment.User" type="XML"/>
            </content>
        </CustomListItem >
    </items>
</GrowingList>

How can I set the binding path of the fragment to the navigation property Creator?

=============================================================
PS: I googled around and find some solution, these solution is not what I want, because it bound the fragment’s data binding tightly to the data model, how the solution works:

first, when binding items path, expand the Creator navigation property:

<GrowingList threshold="10"
            items="{
                path: '/OrderSet',
                paramters: {expand: 'Creator'}
            }">
    <items>
        <CustomListItem >
            <content>
                <core:Fragment fragmentName="xxx.fragment.User" type="XML"/>
            </content>
        </CustomListItem >
    </items>
</GrowingList>

second, change the data binding of the fragment to Creator/xxx:

 <HBox  xmlns="sap.m">
    <items>
        <Image src="{Creator/avatar}"/>
        <VBox>
            <items>
                <Label text="{Creator/name}"/>
                <Label text="{Creator/phone}"/>
            </items>
        </VBox>
    </items>
</HBox>

This makes the fragment useless, if I want to use it in a page displaying a user list because in UserSet, a User doesn’t have a property Creator/name. What I want is the fragment to be general, it can be used anywhere as long as the root binding path is a user entity instance.


Source: xml

Leave a Reply