Skip to content
Nalu
Documentation / Quickstart

Quickstart

Set up Nalu, create an application, a shell and a first controller with its component. Release 4.0.2.

Nalu requires at least Java 17 and GWT 2.12.2. Use the latest GWT version.

Dependencies

Add Nalu and one plugin that fits your widget library. This example uses nalu-plugin-elemental2, which also covers Elemento and Domino-UI based projects.

<dependency>
  <groupId>io.github.nalukit</groupId>
  <artifactId>nalu</artifactId>
  <version>4.0.2</version>
</dependency>
<dependency>
  <groupId>io.github.nalukit</groupId>
  <artifactId>nalu-plugin-elemental2</artifactId>
  <version>4.0.2</version>
</dependency>

Configure the Nalu annotation processor in the maven-compiler-plugin. Use a current plugin version, so that the processor output is logged.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <annotationProcessorPaths>
      <path>
        <groupId>io.github.nalukit</groupId>
        <artifactId>nalu-processor</artifactId>
        <version>4.0.2</version>
      </path>
    </annotationProcessorPaths>
  </configuration>
</plugin>

Choose the plugin

Widget libraryArtifact (group io.github.nalukit)Module to inheritPlugin class
Elemental2, Domino-UInalu-plugin-elemental2io.github.nalukit.nalu.plugin.elemental2.NaluPluginElemental2NaluPluginElemental2
Elementonalu-plugin-elementoio.github.nalukit.nalu.plugin.elemento.NaluPluginElementoNaluPluginElemento
Domino-UI 2nalu-plugin-domino-v2io.github.nalukit.nalu.plugin.domino.v2.NaluPluginDominoV2NaluPluginDominoV2
GWT widgets, GXT, Smart-GWTnalu-plugin-gwt + nalu-plugin-gwt-processorio.github.nalukit.nalu.plugin.gwt.NaluPluginGWTNaluPluginGWT

Choosing the right plugin is essential. The GWT plugin needs its processor nalu-plugin-gwt-processor as an additional annotation processor path and is not available for J2CL.

Module descriptor

Inherit the Nalu module and the module of your plugin, and set the entry point:

<inherits name='io.github.nalukit.nalu.Nalu'/>
<inherits name='io.github.nalukit.nalu.plugin.elemental2.NaluPluginElemental2'/>
<entry-point class='com.example.client.Application'/>

Entry point

The implementation MyApplicationImpl is generated when you build the project, so it is shown as an error until then.

public class Application implements EntryPoint {

  public void onModuleLoad() {
    // MyApplicationImpl is generated by the Nalu processor
    MyApplication application = new MyApplicationImpl();
    // choose the plugin that fits your widget library
    application.run(new NaluPluginElemental2());
  }
}

Application interface and context

The application interface describes the basic behavior of Nalu. The context is a singleton that is injected into every controller, filter, handler and loader.

@Application(startRoute = "/applicationShell/search",
             context = MyApplicationContext.class)
interface MyApplication extends IsApplication {
}
public class MyApplicationContext implements IsContext {

  private String searchName;

  public String getSearchName() { return searchName; }
  public void setSearchName(String searchName) { this.searchName = searchName; }
}

The start route is used if the application is called without a route. It needs a shell and a part that identifies a controller, and it cannot have parameters.

Shell

The shell is the root view of the application. The first part of every route is the name of a shell. The ids inside the shell are the selectors the controllers use.

@Shell("applicationShell")
public class ApplicationShell extends AbstractShell<MyApplicationContext> {

  private HTMLDivElement shell;

  @Override
  public void attachShell() {
    shell = (HTMLDivElement) DomGlobal.document.createElement("div");
    HTMLDivElement content = (HTMLDivElement) DomGlobal.document.createElement("div");
    content.setAttribute("id", "content");   // the selector of a controller
    shell.appendChild(content);
    DomGlobal.document.body.appendChild(shell);
  }

  @Override
  public void detachShell() {
    DomGlobal.document.body.removeChild(shell);
  }
}

Component

A component is the view. Nalu calls render after creating it. Hand your root element over with initElement.

public interface ISearchComponent
    extends IsComponent<ISearchComponent.Controller, HTMLElement> {

  interface Controller extends IsComponent.Controller {
    void doSearch(String name);
  }
}
public class SearchComponent
    extends AbstractComponent<ISearchComponent.Controller, HTMLElement>
    implements ISearchComponent {

  @Override
  public void render() {
    HTMLElement root = (HTMLElement) DomGlobal.document.createElement("div");
    root.textContent = "Search";
    // hand the root element over to Nalu
    initElement(root);
  }
}

Controller

A controller is annotated with @Controller and extends AbstractComponentController with the types of context, component interface and widget base class. It has a public zero-argument constructor.

@Controller(route = "/applicationShell/search/:name",
            selector = "content",
            componentInterface = ISearchComponent.class,
            component = SearchComponent.class)
public class SearchController
    extends AbstractComponentController<MyApplicationContext, ISearchComponent, HTMLElement>
    implements ISearchComponent.Controller {

  private String name;

  @AcceptParameter("name")
  public void setName(String name) throws RoutingInterceptionException {
    this.name = name;
  }

  @Override
  public void start() {
    // the component is created
  }

  @Override
  public void doSearch(String name) {
    router.route("/applicationShell/result/*", name);
  }
}

The controller has access to context, eventBus, router and the component. Parameters are always strings.

Next steps