Class Places

java.lang.Object
org.jboss.elemento.router.Places
All Implemented Interfaces:
Iterable<Map.Entry<Place, Supplier<Page>>>

public class Places extends Object implements Iterable<Map.Entry<Place, Supplier<Page>>>
Represents a collection of places in an application. Each place is associated with a page supplier. Supports nested places and loaders.

public static class EmptyPage implements Page {

    @Override
    public Iterable<HTMLElement> elements(Place place, Parameter parameter, LoadedData data) {
        return emptyList();
    }
}

public static class Application {

    public void entryPoint() {
        /*
        The code builds the following places
        /
        /foo
        /bar
        /level1
        /level1/foo
        /level1/bar
        /level1/level2/foo
        /level1/level2/bar
         */
        Places places = places()
                .add(place("/"), EmptyPage::new)
                .add(place("/foo"), EmptyPage::new)
                .add(place("/bar"), EmptyPage::new)
                .children("/level1", places()
                        .add(place("/"), EmptyPage::new)
                        .add(places() // add siblings!
                                .add(place("/foo"), EmptyPage::new)
                                .add(place("/bar"), EmptyPage::new))
                        .children("/level2", places()
                                .add(place("/foo"), EmptyPage::new)
                                .add(place("/bar"), EmptyPage::new)));

    }
}
  • Method Details

    • places

      public static Places places()
    • iterator

      public Iterator<Map.Entry<Place, Supplier<Page>>> iterator()
      Specified by:
      iterator in interface Iterable<Map.Entry<Place, Supplier<Page>>>
    • add

      public Places add(Place place, Supplier<Page> page)
      Adds a Place and the corresponding page supplier to the collection of places.
    • add

      public Places add(Places places)
      Adds all the places from the given Places object to this places object.
    • children

      public Places children(String path, Places places)
      Adds the children places to the current collection of places. Each child place is created by appending the child's route to the given parent path. The child places and their corresponding page suppliers are added to the current collection.
      Parameters:
      path - the parent path to append to the child routes
      places - the child places to add
    • loader

      public Places loader(Place place, LoadData<?> loader)
      Assigns a given loader for a specific place.