1. Domino Brix
  2. Presenters & views

Presenter basics

Presenters orchestrate lifecycle, routing, slots, events, security, and navigation confirmation around a view. The processor generates the implementation and binds the injected view.

			@BrixPresenter
public class AdminPresenter extends Presenter<AdminView> {
  @Override
  public Set<String> getRoles() {
    return Set.of("admin");
  }

  @Override
  public Authorizer getAuthorizer() {
    return RolesAllowedAuthorizer.INSTANCE;
  }
}

		

Lifecycle hooks

Hook into the full lifecycle to prepare UI, react to routing, or clean up resources.

  1. postConstruct(): after DI; register listeners or prime state.
  2. onActivated(): presenter becomes active after auth/guards.
  3. onBeforeRevealed(): right before revealing the view.
  4. onRevealed(): after the view is attached to its slot.
  5. onStateChanged(): routing token changed while active.
  6. onDeactivated(): tear down listeners and timers.
  7. onRemoved(): DOM detach when the slot removes the view.

Navigation confirmation

Views can block navigation when they have unsaved state. Implement CanConfirmNavigation or ProvidesConfirmNavigation to install a router interceptor during activation.

			SecurityContext sc = (SecurityContext) Brix.get().getCoreComponent().core().getSecurityContext();
sc.setUser(new MyUser());
sc.setUnauthorizedAccessHandler(() -> window.alert("Access denied"));

		

Routing state parameters

Annotate presenter fields with @PathParameter, @QueryParameter, or @FragmentParameter. Generated setters populate fields before activation and keep them updated on token changes. Override onStateChanged() to react.

Child presenters

Use ChildPresenter to activate only when the parent is active and to share routing state. This keeps child views in sync with parent lifecycle.

			public class DepartmentAuthorizer implements Authorizer {
  @Override
  public boolean isAuthorized(IsSecurityContext context, HasRoles hasRoles) {
    return context.isAuthenticated()
        && context.getUser().getAttributes().get("department").ifTypeIs(String.class, dept -> {
             return dept.equals("engineering");
           });
  }
}

		

We are a group of passionate people who love what we do

Donate & Support Us