Interface DateMetadataProvider

All Superinterfaces:
Serializable
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface DateMetadataProvider extends Serializable
A callback that provides metadata for a range of dates, for example to mark dates as not selectable.

The callback runs on the server. The calendar calls it with the range of dates it is about to show, which covers whole months, so a single query can answer for all of them. Server-side validation calls it with the single date being validated. Return an entry only for the dates that have metadata; dates that are not mentioned have none.

Until the callback has answered, the affected dates render in a loading state but stay selectable, so a slow callback does not make the calendar unusable. A date selected before the answer arrives is reported invalid by server-side validation.

Entries can also carry custom CSS part names, so that a theme can style particular dates. See DateMetadata for the details.

Results are cached per month in the browser, but not on the server, so an expensive implementation should cache its own results. Call DatePicker.refreshDateMetadata() when the data behind the callback has changed.

Since:
25.3
Author:
Vaadin Ltd
  • Method Details

    • getDateMetadata

      Collection<DateMetadata> getDateMetadata(DateRange range)
      Gets the metadata for the dates in the given range.
      Parameters:
      range - the range of dates to provide metadata for, covering whole months, never null
      Returns:
      the metadata entries for the dates that have metadata, or an empty collection if none have
    • perDate

      Creates a provider that builds the metadata one date at a time. The given function is called for every date in the requested range, and returns the metadata for that date, or null for a date that has none:
       datePicker.setDateMetadataProvider(DateMetadataProvider.perDate(
               date -> isFullyBooked(date) ? new DateMetadata(date, true)
                       : null));
       
      The function is called once per date, and a range can cover up to a year, so it has to answer from memory. A function that queries a backend would query it once per date; implement the provider directly instead, so that a single query can answer for the whole range.
      Parameters:
      generator - the function that returns the metadata for a single date, or null for a date that has none, not null
      Returns:
      a provider backed by the given function
      Since:
      25.3