To allow the dialog’s OK, Yes, or No button to perform an operation such as a commit or rollback, you use a dialog listener. For example, the following pop-up dialog includes a backing bean method for handling when the pop-up is canceled via the Cancel button or close icon (popupCanceledListener) or the dialog is closed via the OK button (dialogListener):
<af:popup contentDelivery="lazyUncached"
popupCanceledListener="#{DialogBean.handlePopupCancel}">
<af:dialog dialogListener="#{DialogBean.handleDialogClose}">
<!-- Input form defined here -->
</af:dialog>
</af:popup>
The backing bean implements the handlePopupCancel and handleDialogClose methods, as shown in the following code sample. Note that to determine which button was clicked, the handleDialogClose method uses the getOutcome method of DialogEvent.
…
public void handleDialogClose(DialogEvent dialogEvent) {
if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.ok)) {
BindingContext bindingctx = BindingContext.getCurrent();
BindingContainer bindings = bindingctx.getCurrentBindingsEntry();
OperationBinding operationBinding =
bindings.getOperationBinding("Commit");
Object result = operationBinding.execute();
}
}
---
public void handlePopupCancel(PopupCanceledEvent popupCanceledEvent) {
BindingContext bindingctx = BindingContext.getCurrent();
BindingContainer bindings = bindingctx.getCurrentBindingsEntry();
OperationBinding operationBinding =
bindings.getOperationBinding("Rollback");
Object result = operationBinding.execute();
}
No comments:
Post a Comment