cancel
Showing results for 
Search instead for 
Did you mean: 

How to utilize the Fragment effectively?

Jayakrishnan
Active Participant
0 Kudos
1,514

Hi Everyone,

I am working on Custom SAPUI5 Development. In our usual case, we do use fragment for Dialog/Select Dialog/Valuhelp functionalities. I have few questions regarding the re usability of fragment?

1. In case if i have Edit and Create scenario, can we use same fragment.xml file? if all the fields are same for both create and edit? When i try to implement this, i usually get duplicate id issue, fragment not instantiated etc.? Is it necessary that i need to create two separate fragment for edit/create as like SAPUi5 Form examples.

Please share your views on this .

Thank you,

Regards,

JK.

Accepted Solutions (0)

Answers (2)

Answers (2)

junwu
Active Contributor
0 Kudos
sap.ui.xmlfragment([sId], sFragmentName,[oController]);

or Fragment.load

the id parameter should save you.

Fragment.load({
					id: oView.getId(),
					name:"sap.ui.demo.walkthrough.view.HelloDialog"}).then(function(oDialog){// connect dialog to the root view of this component (models, lifecycle)
					oView.addDependent(oDialog);
					oDialog.open();});
Jayakrishnan
Active Participant
0 Kudos

Hi jun.wu5, Thanks fro your input, i will check and let you know.

junwu
Active Contributor
0 Kudos

for each use case, you have to give a different id.

0 Kudos

Hi Jayakrishna,

If you want to use the fragment within only one page. Then you can mention it in same view under dependents tag ( Inside page ) and you can open it in controller ( It wont through duplicate id error ).

<dependents>
<Popover >
<List>
<StandardListItem>
</StandardListItem>
</List>
</Popover>
</dependents>

If you want to use in different screens. Better to go with the two way binding ( Mention model name and property for all the elements ) and get the values in controller.

And the last point , Destroythe dialog box / popover in onclose event.

Jayakrishnan
Active Participant
0 Kudos

Hi ajay.deshetty ,Thanks for your input, i will try and let you know.