Fragment Class
The UI5 Antares library includes a built-in class (FragmentCL) providing a set of public methods to load the contents of a fragment file (*.fragment.xml) and to open a dialog or a popover.
Info
The Custom Control From Fragment and Custom Content From Fragment methods of the Entry classes also use the FragmentCL class.
Constructor
In order to utilise the functionality of FragmentCL, it is necessary to initialise the object.
Parameter | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
controller | sap.ui.core.mvc.Controller | Yes | The controller object (usually this object) |
|
fragmentPath | string |
Yes | The path of the fragment whose content will be loaded or opened | |
openByControl? | sap.ui.core.Control | No | If the loaded fragment contains a popover, this parameter determines which control the popover opens next to. For example: sap.m.Button |
Example
Let us assume that we have created a file with the extension .fragment.xml and the following content. Our objective is to open the dialog in the controller.
<core:FragmentDefinition
xmlns:form="sap.ui.layout.form"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Dialog title="Create New Product">
<form:SimpleForm>
<form:content>
<Label text="Product ID" />
<MaskInput
mask="CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC"
value="{ID}"
placeholderSymbol="_"
>
<rules>
<MaskInputRule
maskFormatSymbol="C"
regex="[a-f0-9]"
/>
</rules>
</MaskInput>
<Label text="Name" />
<Input value="{name}" />
<Label text="Description" />
<TextArea
value="{description}"
rows="5"
/>
<Label text="Price" />
<Slider
width="100%"
min="1000"
max="100000"
showAdvancedTooltip="true"
showHandleTooltip="true"
inputsAsTooltips="true"
enableTickmarks="true"
step="1000"
class="sapUiMediumMarginBottom"
value="{price}"
/>
<Label text="Currency" />
<ComboBox selectedKey="{currency}">
<items>
<core:Item
key="EUR"
text="Euro"
/>
<core:Item
key="USD"
text="US Dollar"
/>
<core:Item
key="TRY"
text="Turkish Lira"
/>
</items>
</ComboBox>
</form:content>
</form:SimpleForm>
<beginButton>
<Button
text="Complete"
press="onCompleteProduct"
/>
</beginButton>
<endButton>
<Button
text="Close"
press="onCloseProductDialog"
/>
</endButton>
</Dialog>
</core:FragmentDefinition>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Load Content
To load the content from a fragment file, the load(): Promise<Control | Control[]> method can be utilized.
Info
In the event that the fragment contains more than one UI control, the load() method will return an array containing the UI controls. Conversely, for single content, the load() method will return the UI control itself.
Attention
Please be aware that the load() method is asynchronous and must be awaited.
Example
Let us assume that we have created a file with the extension .fragment.xml with the following content. We would now like to use the sap.m.Text in the controller.
<core:FragmentDefinition
xmlns:form="sap.ui.layout.form"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Text text="My Text" />
</core:FragmentDefinition>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Open Dialog or Popover
There are two distinct methods for opening a dialog or popover from a fragment file.
Attention
Please be advised that both methods support only the following dialog and popover classes:
Tip
Both methods include an optional parameter named viewDependent: boolean
. Should you wish to add the dialog or popover as a dependent to your view, please set this parameter to true.
Open Sync
In order to utilise the open() method, it is essential to first execute the load() method.
To utilize the open() method, it is essential to first execute the load() method.
Info
The open() method returns the dialog or popover loaded from a fragment using the load() method.
Attention
When opening a popover, it is necessary to set the control that the popover opens next to. Please refer to the constructor documentation for further information.
Dialog Example
Let us assume that we have created a file with the extension .fragment.xml with the following content. We would now like to open the dialog in the controller.
<core:FragmentDefinition
xmlns:form="sap.ui.layout.form"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Dialog title="Create New Product">
<form:SimpleForm>
<form:content>
<Label text="Product ID" />
<MaskInput
mask="CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC"
value="{ID}"
placeholderSymbol="_"
>
<rules>
<MaskInputRule
maskFormatSymbol="C"
regex="[a-f0-9]"
/>
</rules>
</MaskInput>
<Label text="Name" />
<Input value="{name}" />
<Label text="Description" />
<TextArea
value="{description}"
rows="5"
/>
</form:content>
</form:SimpleForm>
<beginButton>
<Button
text="Complete"
press="onCompleteProduct"
/>
</beginButton>
<endButton>
<Button
text="Close"
press="onCloseProductDialog"
/>
</endButton>
</Dialog>
</core:FragmentDefinition>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Popover Example
Let us assume that we have created a file with the extension .fragment.xml and the following content. We would now like to open the popover in the controller.
<core:FragmentDefinition
xmlns:form="sap.ui.layout.form"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Popover>
<content>
<Text text="Test" />
<Button
text="Finish"
press="onFinish"
/>
</content>
</Popover>
</core:FragmentDefinition>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Open Async
The openAsync() method first executes the load() method internally, and then opens the dialog or popover.
Info
The openAsync() method returns the dialog or popover loaded from a fragment.
Attention
When opening a popover, it is necessary to set the control that the popover opens next to. Please refer to the constructor documentation for further information.
Tip
Please be aware that the openAsync() method is asynchronous. To retrieve the dialog or popover, please await the openAsync() method.
Dialog Example
Let us assume that we have created a file with the extension .fragment.xml and the following content. We would now like to open the dialog in the controller.
<core:FragmentDefinition
xmlns:form="sap.ui.layout.form"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Dialog title="Create New Product">
<form:SimpleForm>
<form:content>
<Label text="Product ID" />
<MaskInput
mask="CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC"
value="{ID}"
placeholderSymbol="_"
>
<rules>
<MaskInputRule
maskFormatSymbol="C"
regex="[a-f0-9]"
/>
</rules>
</MaskInput>
<Label text="Name" />
<Input value="{name}" />
<Label text="Description" />
<TextArea
value="{description}"
rows="5"
/>
</form:content>
</form:SimpleForm>
<beginButton>
<Button
text="Complete"
press="onCompleteProduct"
/>
</beginButton>
<endButton>
<Button
text="Close"
press="onCloseProductDialog"
/>
</endButton>
</Dialog>
</core:FragmentDefinition>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Popover Example
Let us assume that we have created a file with the extension .fragment.xml and the following content. We would now like to open the popover in the controller.
<core:FragmentDefinition
xmlns:form="sap.ui.layout.form"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Popover>
<content>
<Text text="Test" />
<Button
text="Finish"
press="onFinish"
/>
</content>
</Popover>
</core:FragmentDefinition>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Close Dialog or Popover
To close the dialog or popover that was opened by any of the approaches listed below, you will need to use the close() or closeAndDestroy() method.
2) openAsync()
Attention
Please be advised that it is your responsibility to destroy the content after using the close() method. This can be achieved by using the destroyFragmentContent() method. Alternatively, if you use the closeAndDestroy() method, the content will be destroyed automatically.
Example
Let us assume that we have created a file with the extension .fragment.xml with the following content. We would now like to open the dialog in the controller. When the user presses the Close button, we will close the dialog and destroy it.
<core:FragmentDefinition
xmlns:form="sap.ui.layout.form"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Dialog title="Create New Product">
<form:SimpleForm>
<form:content>
<Label text="Product ID" />
<MaskInput
mask="CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC"
value="{ID}"
placeholderSymbol="_"
>
<rules>
<MaskInputRule
maskFormatSymbol="C"
regex="[a-f0-9]"
/>
</rules>
</MaskInput>
<Label text="Name" />
<Input value="{name}" />
<Label text="Description" />
<TextArea
value="{description}"
rows="5"
/>
</form:content>
</form:SimpleForm>
<beginButton>
<Button
text="Complete"
press="onCompleteProduct"
/>
</beginButton>
<endButton>
<Button
text="Close"
press="onCloseDialog"
/>
</endButton>
</Dialog>
</core:FragmentDefinition>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Get Fragment Content
To retrieve the content loaded from a fragment file using the load() or openAsync() method, the getFragmentContent() method can be utilized.
Returns | Description |
---|---|
Control | Control[] | Returns the control or controls loaded from a fragment file using the load() or openAsync() method |
Destroy Fragment Content
To destroy the content loaded from a fragment using the load() or openAsync() methods, the destroyFragmentContent() method can be utilized.
Attention
Should you wish to destroy the content of the dialog when the user presses the ESC button on the keyboard, we advise you to use the setAutoDestroyOnESC(destroy: boolean) method and set the parameter of the method to true. Otherwise, you will be responsible for destroying the content when the user presses the ESC button. Please note that if the content is not destroyed in each ESC event, the dialog cannot be loaded again.
Example
Let us assume that we have created a file with the extension .fragment.xml and the following content. We would now like to open the dialog in the controller. When the user presses the Close button, we will close the dialog and destroy it.
<core:FragmentDefinition
xmlns:form="sap.ui.layout.form"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Dialog title="Create New Product">
<form:SimpleForm>
<form:content>
<Label text="Product ID" />
<MaskInput
mask="CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC"
value="{ID}"
placeholderSymbol="_"
>
<rules>
<MaskInputRule
maskFormatSymbol="C"
regex="[a-f0-9]"
/>
</rules>
</MaskInput>
<Label text="Name" />
<Input value="{name}" />
<Label text="Description" />
<TextArea
value="{description}"
rows="5"
/>
</form:content>
</form:SimpleForm>
<beginButton>
<Button
text="Complete"
press="onCompleteProduct"
/>
</beginButton>
<endButton>
<Button
text="Close"
press="onCloseDialog"
/>
</endButton>
</Dialog>
</core:FragmentDefinition>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|