Step 17: Fragment Callbacks

介绍

Now that we have integrated the dialog, it’s time to add some user interaction. The user will definitely want to close the dialog again at some point, so we add a button to close the dialog and assign an event handler.

1.练习效果

Step 17: Fragment Callbacks - 第1张  | 优通SAP

2.源码

You can view and download all files at Walkthrough – Step 17.

webapp/controller/HelloPanel.controller.js

As previously described, fragments are pure UI reuse artifacts and do not have a controller. The third parameter of the
sap.ui.xmlfragment function is optional and allows passing in a reference to a (controller) object. For our
dialog we reference the HelloPanel controller. However, the third parameter does not necessarily have to be a
controller but can be any object. Just don’t forget the this keyword.

The event handler function is put into the same controller file and it closes the
dialog by accessing the internal helper function that returns the dialog.

3.webapp/view/HelloDialog.fragment.xml

In the fragment definition, we add a button to the beginButton aggregation of the dialog. The press handler is referring to an
event handler called .onCloseDialog, and since we passed in the reference to the HelloPanel
controller, the method will be invoked there when the button is pressed. The dialog has an aggregation named
beginButton as well as endButton. Placing buttons in both of these aggregations makes sure that
the beginButton is placed before the endButton on the UI. What before means,
however, depends on the text direction of the current language. We therefore use the terms begin and
end as a synonym to “left” and “right”. In languages with left-to-right direction, the
beginButton will be rendered left, the endButton on the right side of the dialog footer; in
right-to-left mode for specific languages the order is switched.

4.webapp/i18n/i18n.properties

The text bundle is extended by the new text for the dialog’s close button.

留下一个回复

你的email不会被公开。

four × two =