Skip to content
Nalu
Documentation / API reference

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
naluCore: annotations, router, base classes, events, GWT module io.github.nalukit.nalu.Nalu
nalu-processorAnnotation processor that generates the application, router and controller code (compile time only)
nalu-plugin-core-webDefault web routing plugin for hash and clean URL routing
nalu-plugin-elemental2Plugin for Elemental2, Elemento and Domino-UI based widget libraries
nalu-plugin-elementoPlugin for IsElement<E> of Elemento
nalu-plugin-domino-v2Plugin for IsElement of Domino-UI 2
nalu-plugin-gwt / nalu-plugin-gwt-processorPlugin and processor for GWT widgets. Not for J2CL

@Application

On an interface that extends IsApplication. Defines the basic behavior of Nalu.

AttributeDefaultMeaning
startRouterequiredRoute used when the application starts without a route. Needs a shell and a controller part, no parameters
contextrequiredClass of the application context
loader / postLoadernoneLoader executed at start / after all modules are loaded
isUsingHistorytrueSupport browser history, so the application can reload
routingModeHASHRoutingMode.HASH or RoutingMode.CLEAN_URL
usingHashtruefalse has the same effect as CLEAN_URL
basePathemptyPart of the URL in front of the routes. Only with CLEAN_URL
usingBaseHreffalseSet the base href for relative resources
usingTrailingSlashfalseEnd routes with /
usingUnderscoreForParametersInUrlfalseUse _ before parameters in the URL
stayOnSitefalseWith an empty hash, add a history entry with the start route
alertPresenter / confirmPresenterplugin dialogsCustom alert and confirm dialog
illegalRouteTargetnoneRoute to show instead of an error message for an illegal route

Related annotations

AnnotationPurpose
@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

AnnotationAttributesUsed on
@Shellvalue: name of the shellClass extending AbstractShell. Implement attachShell and detachShell
@Controllerroute (one or several), selector, componentInterface, componentClass extending AbstractComponentController<C, V, W>
@AcceptParametervalue: parameter nameMethod with one String parameter that may throw RoutingInterceptionException
@CompositeControllercomponentInterface, componentClass extending AbstractCompositeController
@Compositename, compositeController, selector, condition, scopeA controller, to add a composite
@BlockControllername, componentInterface, component, conditionBlock shown by events, independent of routing
@PopUpControllername, componentInterface, component, condition, alwaysRenderComponentPop-up shown by a ShowPopUpEvent
@ErrorPopUpControllercomponentInterface, componentPop-up for NaluErrorEvent
@Handler–Class extending AbstractHandler<C>
@EventHandler–Method that handles an event

Controller life cycle

MethodWhen
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

  1. Change the groupId from com.github.nalukit to io.github.nalukit.
  2. Replace all imports from com.github.nalukit by io.github.nalukit.
  3. Update the inherits in your module descriptor from com.github.nalukit to io.github.nalukit.

More information