API reference
Annotations, base classes, life cycles and plugins of Nalu 4.0.2. Everything in io.github.nalukit.nalu.internal.* and everything annotated with @NaluInternalUse is private API.
Artifacts
| Artifact (group io.github.nalukit) | Purpose |
|---|---|
nalu | Core: annotations, router, base classes, events, GWT module io.github.nalukit.nalu.Nalu |
nalu-processor | Annotation processor that generates the application, router and controller code (compile time only) |
nalu-plugin-core-web | Default web routing plugin for hash and clean URL routing |
nalu-plugin-elemental2 | Plugin for Elemental2, Elemento and Domino-UI based widget libraries |
nalu-plugin-elemento | Plugin for IsElement<E> of Elemento |
nalu-plugin-domino-v2 | Plugin for IsElement of Domino-UI 2 |
nalu-plugin-gwt / nalu-plugin-gwt-processor | Plugin and processor for GWT widgets. Not for J2CL |
@Application
On an interface that extends IsApplication. Defines the basic behavior of Nalu.
| Attribute | Default | Meaning |
|---|---|---|
startRoute | required | Route used when the application starts without a route. Needs a shell and a controller part, no parameters |
context | required | Class of the application context |
loader / postLoader | none | Loader executed at start / after all modules are loaded |
isUsingHistory | true | Support browser history, so the application can reload |
routingMode | HASH | RoutingMode.HASH or RoutingMode.CLEAN_URL |
usingHash | true | false has the same effect as CLEAN_URL |
basePath | empty | Part of the URL in front of the routes. Only with CLEAN_URL |
usingBaseHref | false | Set the base href for relative resources |
usingTrailingSlash | false | End routes with / |
usingUnderscoreForParametersInUrl | false | Use _ before parameters in the URL |
stayOnSite | false | With an empty hash, add a history entry with the start route |
alertPresenter / confirmPresenter | plugin dialogs | Custom alert and confirm dialog |
illegalRouteTarget | none | Route to show instead of an error message for an illegal route |
Related annotations
| Annotation | Purpose |
|---|---|
@Filters(filterClasses) | Filters that can stop and redirect routings |
@PopUpFilters(filterClasses) | Filters for pop-ups |
@Modules({…}) | Modules of the application |
@Logger(clientLogger, logger) | Client and server logging |
@Version("1.0.1") | Application version |
@Tracker(Tracker.class) | Routing tracking |
Controllers, components and shells
| Annotation | Attributes | Used on |
|---|---|---|
@Shell | value: name of the shell | Class extending AbstractShell. Implement attachShell and detachShell |
@Controller | route (one or several), selector, componentInterface, component | Class extending AbstractComponentController<C, V, W> |
@AcceptParameter | value: parameter name | Method with one String parameter that may throw RoutingInterceptionException |
@CompositeController | componentInterface, component | Class extending AbstractCompositeController |
@Composite | name, compositeController, selector, condition, scope | A controller, to add a composite |
@BlockController | name, componentInterface, component, condition | Block shown by events, independent of routing |
@PopUpController | name, componentInterface, component, condition, alwaysRenderComponent | Pop-up shown by a ShowPopUpEvent |
@ErrorPopUpController | componentInterface, component | Pop-up for NaluErrorEvent |
@Handler | – | Class extending AbstractHandler<C> |
@EventHandler | – | Method that handles an event |
Controller life cycle
| Method | When |
|---|---|
bind(loader) | Before the component is created, not for cached controllers. Asynchronous: call loader.continueLoading() |
start() | After the component is created, not for cached controllers |
activate() | After start, and every time a cached controller becomes active |
mayStop() | Before a new routing. A returned string is shown and aborts the routing |
unbind(continue, stop) | After mayStop did not interrupt. Asynchronous: always give control back with the continue or stop command |
deactivate() | Before stop, and every time a cached controller becomes inactive |
stop() | After a successful routing, not for cached controllers |
Handler management
Handler registrations added to the handlerRegistrations of a component are removed after the stop method of its controller. In controllers and composites, register event bus handlers in activate: they are removed after deactivate. Global registrations stay until the controller is stopped.
Composites
A composite is a controller and component pair that cannot be routed to. It is added to a controller with @Composite (several with @Composites), has access to event bus, router and context, and can be loaded conditionally.
Loader
A loader runs asynchronous actions at application start, before the first route. Do not route inside a loader. Return control with finishLoadCommand.finishLoading().
public class MyLoader extends AbstractLoader<MyContext> {
@Override
public void load(FinishLoadCommand finishLoadCommand) {
// load data, store it in the context ...
finishLoadCommand.finishLoading(); // give control back to Nalu
}
}
With modules, the order is: application loader, module loaders, postLoader.
Handler
A handler behaves like a controller without a visual component. Nalu creates handlers at application start, and an event triggers them. Context, event bus and router are injected.
@Handler
public class MyHandler extends AbstractHandler<MyApplicationContext> {
@Override
public void bind() {
this.eventBus.addHandler(MyEvent.TYPE, e -> {
// your code here
});
}
}
Event bus and events
Nalu uses the event classes of org.gwtproject.events, which are ready for GWT 3 and J2CL. Controllers, composites, handlers, filters and loaders have access to the same application wide event bus. Methods annotated with @EventHandler handle events.
In a multi module project, NaluApplicationEvent reaches all modules and the main application:
this.eventBus.fireEvent(NaluApplicationEvent.create()
.event("selectNavigationItem")
.data("navigationItem", "home"));
Error handling
Nalu reports routing loops, illegal routes, unknown selectors and missing elements by firing a NaluErrorEvent. You can fire application errors with it as well and show them with an @ErrorPopUpController or a handler. Since 2.0.0 there is no error route.
NaluErrorEvent.createApplicationError()
.id("myErrorId")
.route("/application/person/search")
.message("Something went wrong")
.data("key01", "first parameter");
Multi module projects
A module extends IsModule and has its own context. The application loads modules with @Modules. Nalu adds the components and routes of all modules to the application configuration.
@Module(name = "myModule01", context = MyModule01Context.class)
public interface MyModule01 extends IsModule<MyModuleContext> {
}
@Application(startRoute = "/loginShell/login", context = MyApplicationContext.class)
@Modules({ MyModule01.class, MyModule02.class })
interface MyApplication extends IsApplication {
}
SEO support
Nalu collects SEO information during a routing and updates the page title and meta tags at the end of the routing. Setters exist for title, description, keywords, robots, the og:* tags and the twitter:* tags.
SeoDataProvider.get().setTitle("Edit person");
SeoDataProvider.get().setDescription("Edit the selected person");
SeoDataProvider.get().setRobots("index,follow");
Tracking
With @Tracker on the application interface, Nalu reports every routing to a tracker that implements IsTracker.
Parameter constraints
Define a rule as an interface that extends IsParameterConstraintRule and is annotated with @ParameterConstraintRule and constraints such as @MaxLength, @MinLength, @NotEmpty, @Pattern, @WhiteListing and @BlackListing. Apply it with @ParameterConstraint(rule, illegalParameterRoute) on the method annotated with @AcceptParameter. An illegal parameter routes to illegalParameterRoute.
Logger and version
@Logger activates logging to the browser console (clientLogger) and to your server (logger). @Version("1.0.1") sets the application version, which you read from context.getApplicationVersion() if the context extends AbstractModuleContext. The system property nalu.application.version overrides it.
Migration to io.github
- Change the groupId from
com.github.nalukittoio.github.nalukit. - Replace all imports from
com.github.nalukitbyio.github.nalukit. - Update the
inheritsin your module descriptor fromcom.github.nalukittoio.github.nalukit.
More information
- Controllers & composites, event bus and more: the full documentation in the sidebar.
- nalu-examples: example projects.