3.5.4.4. NotificationFacet

NotificationFacet is a facet that provides an ability to pre-configure a notification. Declarative definition of the replaces existing Notifications.create() method. NotificationFacet is defined in the facets element of the screen XML descriptor.

Component’s XML-name: notification.

Usage example:

<facets>
    <notification id="notification"
                  caption="msg://notificationFacet"
                  description="msg://notificationDescription"
                  type="TRAY"/>
</facets>

The screen configured with NotificationFacet can be shown explicitly using the show() method:

@Inject
protected NotificationFacet notification;

public void showNotification() {
    notification.show();
}

notification has the following attributes:

  • onAction attribute contains the action identifier. After this action is performed, the notification should be shown.

    <actions>
        <action id="notificationAction"/>
    </actions>
    <facets>
        <notification id="notification"
                      caption="msg://notificationFacet"
                      onAction="notificationAction"
                      type="TRAY"/>
    </facets>
  • onButton attribute contains the button identifier. After this button is clicked, the notification should be shown.

    <facets>
        <notification id="notification"
                      caption="msg://notificationFacet"
                      onButton="notificationBtn"
                      type="TRAY"/>
    </facets>
    <layout>
        <button id="notificationBtn"
                caption="Show notification"/>
    </layout>
  • If the contentMode attribute is set to ContentMode.HTML, you can enable HTML sanitization for the notification content using the htmlSanitizerEnabled attribute.

    <facets>
        <notification id="notificationFacetOn"
                      caption="NotificationFacet with Sanitizer"
                      contentMode="HTML"
                      htmlSanitizerEnabled="true"
                      onButton="showNotificationFacetOnBtn"
                      type="TRAY"/>
        <notification id="notificationFacetOff"
                      caption="NotificationFacet without Sanitizer"
                      contentMode="HTML"
                      htmlSanitizerEnabled="false"
                      onButton="showNotificationFacetOffBtn"
                      type="TRAY"/>
    </facets>

    The htmlSanitizerEnabled attribute overrides the value of global cuba.web.htmlSanitizerEnabled configuration property.