Interface PageTitleGenerator

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 PageTitleGenerator extends Serializable
Resolves a navigation target title dynamically without requiring an instance of the navigation target.

This is the stateless counterpart of HasDynamicTitle. While HasDynamicTitle.getPageTitle() is an instance method and therefore only usable once the view has been created, a PageTitleGenerator is resolved purely from the navigation target class and its RouteParameters. This makes it suitable for use cases that need the title of a route that is not (and should not be) instantiated, such as breadcrumbs, menus or other navigation aids that render the titles of a whole trail of routes.

A generator is referenced from a route through DynamicPageTitle:

 @Route("products/:productId")
 @DynamicPageTitle(ProductTitleGenerator.class)
 public class ProductView extends Div {
     // ...
 }

 public class ProductTitleGenerator implements PageTitleGenerator {
     @Override
     public String generatePageTitle(PageTitleContext context) {
         String id = context.routeParameters().get("productId").orElse("");
         return "Product " + id;
     }
 }
 
Implementations must be stateless and are expected to be cheap to create: they are instantiated through the application Instantiator (so dependency injection is available) every time a title is resolved, never the navigation target itself.
Since:
25.2
Author:
Vaadin Ltd
  • Method Summary

    Modifier and Type
    Method
    Description
    Generates the title for the navigation target described by the given context.
  • Method Details

    • generatePageTitle

      String generatePageTitle(PageTitleContext context)
      Generates the title for the navigation target described by the given context.
      Parameters:
      context - the context describing the navigation target and its route parameters, not null
      Returns:
      the title to use for the navigation target, not null