Skip to Content
0
Apr 26, 2018 at 09:02 AM

How to access and pass the ID of an object in an XML-View without displaying it?

140 Views Last edit Apr 26, 2018 at 09:06 AM 3 rev

Hello,

im currently creating a CRUD-application to learn SAPUI5. The CRUD-operations itself work and my content gets saved to my database. Until now I was showing the ID of every object in my table as content of a cell. So it was pretty easy to catch it in my controller, I could use that ID for my delete and update operations. Later on, I don't want to do that because the user does not need to know which ID this object has in my database. But as said above I need the ID in order to perfom my update and delete operation.

So here is the relevant part of my view:

<columns>
    <Column><header><Text text="FIRSTNAME"/></header></Column>
    <Column><header><Text text="LASTNAME"/></header></Column>
    <Column><header><Text text="ID"/></header></Column>
</columns>
<items>
    <ColumnListItem type="Navigation" press="onListPress">
    <cells>
        <ObjectIdentifier text="{Person>FIRSTNAME}"/>
        <ObjectIdentifier text="{Person>LASTNAME}"/>
	<ObjectIdentifier text="{Person>ID}"/>
    </cells>
    </ColumnListItem>
</columns>

So what did I try until now to solve my problem: I found out that there is the option to use custom data and tried to store it there e.g. by binding it to a button, that worked and I could use that data in my controller. The problem that remains for me is, I did not find a best practice until now, how that should be done in SAPUI5, on which element should the ID be bound, is there any?

Thank you for your time and help in this case.