cancel
Showing results for 
Search instead for 
Did you mean: 

Binding associated entity in XML View

0 Kudos

Dear UI5 experts,

Dear Jun Wu, I hope you could help me out with this.

I have 2 entites/entitySets (Z001, ZAttachment) and 1 association (Z001ToZattachment) which describes the connection between them and has a 0..n cardinality. The backend coding is done and everything works fine.

Z001 entity has the following fields: OrderID, OrderName

ZAttachment has: OrderID, FileGuid, FileName

In my XML view I would like to bind both the fields from Z001 and the rows/records of Zattachment into the UploadCollection. It looks something like this:

<Input value="{OrderId}"></Input>	
<Input value="{OrderName}"></Input>	

<UploadCollection items="{path:'Z001Set', parameters: { expand: 'Z001ToAttachment' }}">
	<items>
		<UploadCollectionItem fileName="{Z001ToAttachment/FileName}"></UploadCollectionItem>
	</items>
</UploadCollection>

In my controller I create the Entry like this:

	var Z001 = this.getModel().createEntry("/Z001Set", {
		
	}).bind(this);
	
	this.getView().setBindingContext(Z001);

But the upload collection wont work, console says: "Missing template for factory function for aggregated items of Element sap.m.UploadCollection". I know i could not bind the data right, the question is how shall it be done?

Thanks

Tu

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member221786
Active Participant
0 Kudos

Hi Tu,

your binding looks a little bit off.

I think you want to bind the attachments of an Entry "Z001Set", is that right?

In that case you have to do the binding like this:

<UploadCollection items="{Z001ToAttachment}">
	<items>
		<UploadCollectionItem fileName="{FileName}"></UploadCollectionItem>
	</items>
</UploadCollection>

Small addendum: Z001ToAttachment has to be an array. I don't think the associations get created with createEntry so you have to add them manually.

Hope this helps. Could be wrong as I didn't try this out by myself.

Greetings
Sebastian

0 Kudos

Hi Sebastian,

Yes, I want to bind the attachments of an Entry "Z001Set". I've tried your proposed solution, but that did not work.

But i think you're right, that createEntry does not create the association automatically. How can I do this?

Thanks

Tu

former_member221786
Active Participant
0 Kudos

Hi Tu,

the proper way is to create Z001Set first and save it.
When you read the entity with expand the next time you get an empty array for Z001ToAttachment.
In that case your binding works (but should not show anything because the array is empty).

When there is an persisted Entity Z001Set you are able to create an entity for ZAttachmentSet with reference to your Z001Set Entity.
After that attachments will be displayed.

I strongly recommend that you do it this way. Working with non persisted entities and associations is ugly, time consuming and frustrating.

Greetings
Sebastian