Package org.jboss.elemento.router
Class PlaceManager
java.lang.Object
org.jboss.elemento.router.PlaceManager
The place manager is the central part of the router. It keeps track of registered places, handles navigation events, and
updates the DOM accordingly. The place manager can be customized using builder like methods and has a
start()
method
to show the initial page.
public static class TimeLoader implements LoadData<String> {
@Override
public Promise<String> load(Place place, Parameter parameter) {
String area = parameter.get("area");
String location = parameter.get("location");
String url = "https://worldtimeapi.org/api/timezone/" + area + "/" + location;
return fetch(url)
.then(Response::json)
.then(json -> {
JsPropertyMap<String> map = Js.cast(json);
return Promise.resolve(map.get("datetime"));
});
}
}
public static class TimePage implements Page {
@Override
public Iterable<HTMLElement> elements(Place place, Parameter parameter, LoadedData data) {
String area = parameter.get("area");
String location = parameter.get("location");
String currentTime = data.get();
return asList(
h(1, "Current time").element(),
p()
.add("It's ")
.add(span().text(currentTime))
.add(" in " + area + "/" + location)
.element());
}
}
public static class HomePage implements Page {
@Override
public Iterable<HTMLElement> elements(Place place, Parameter parameter, LoadedData data) {
return asList(
h(1, "Welcome").element(),
p()
.add("What time is it in ")
.add(a("/time/Europe/Berlin").text("Berlin"))
.add("?")
.element());
}
}
public static class Application {
public void entryPoint() {
body().add(div().id("main"));
Places places = Places.places()
.add(place("/"), HomePage::new)
.add(place("/time/:area/:location")
.loader(new TimeLoader()), HomePage::new);
PlaceManager placeManager = new PlaceManager()
.root(By.id("main"))
.register(places);
placeManager.start();
}
}
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionafterPlace
(AfterPlaceHandler afterPlace) beforePlace
(BeforePlaceHandler beforePlace) current()
void
linkSelector
(String selector) linkSelector
(String selector, boolean not) linkSelector
(By selector) linkSelector
(By selector, boolean not) root
(HTMLElement element) root
(Supplier<HTMLElement> root) void
start()
-
Constructor Details
-
PlaceManager
public PlaceManager()
-
-
Method Details
-
base
-
root
-
root
-
root
-
root
-
title
-
notFound
-
noData
-
beforePlace
-
afterPlace
-
linkSelector
-
linkSelector
-
linkSelector
-
linkSelector
-
register
-
register
-
current
-
place
-
start
public void start() -
goTo
-
href
-