Record Class WebNotificationOptions

java.lang.Object
java.lang.Record
com.vaadin.flow.component.webnotification.WebNotificationOptions
Record Components:
body - the text shown below the title, or null for none
icon - the URL of an image shown with the notification, or null for the browser's default
tag - the group the notification belongs to, or null for none; showing a notification replaces a notification with the same tag that is still visible instead of adding another one
renotify - whether replacing a notification with the same tag alerts the user again with sound or vibration; true requires a tag and cannot be combined with silent
requireInteraction - whether the notification stays visible until the user clicks or dismisses it instead of closing automatically after a while
silent - whether the notification is shown without sound or vibration
All Implemented Interfaces:
Serializable

public record WebNotificationOptions(@Nullable String body, @Nullable String icon, @Nullable String tag, boolean renotify, boolean requireInteraction, boolean silent) extends Record implements Serializable
What a notification shows besides its title, and how it behaves. Every setting is optional: a text that is not set is left out, and a flag that is not set is false, so a notification behaves the same in every browser. Create instances with builder():

 WebNotificationOptions options = WebNotificationOptions.builder()
         .body("Report for March is ready").tag("report").build();
 
How a setting is presented is up to the browser and the operating system, and some ignore settings they do not support — for example, Firefox and Safari ignore requireInteraction.
See Also:
  • Constructor Details

    • WebNotificationOptions

      public WebNotificationOptions(@Nullable String body, @Nullable String icon, @Nullable String tag, boolean renotify, boolean requireInteraction, boolean silent)
      Validates the combination of settings.
      Throws:
      IllegalArgumentException - if renotify is true without a tag or together with silent, which browsers reject
  • Method Details

    • builder

      public static WebNotificationOptions.Builder builder()
      Creates a builder with no settings set.
      Returns:
      a new builder
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • body

      public @Nullable String body()
      Returns the value of the body record component.
      Returns:
      the value of the body record component
    • icon

      public @Nullable String icon()
      Returns the value of the icon record component.
      Returns:
      the value of the icon record component
    • tag

      public @Nullable String tag()
      Returns the value of the tag record component.
      Returns:
      the value of the tag record component
    • renotify

      public boolean renotify()
      Returns the value of the renotify record component.
      Returns:
      the value of the renotify record component
    • requireInteraction

      public boolean requireInteraction()
      Returns the value of the requireInteraction record component.
      Returns:
      the value of the requireInteraction record component
    • silent

      public boolean silent()
      Returns the value of the silent record component.
      Returns:
      the value of the silent record component