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;
}
}
Hook into the full lifecycle to prepare UI, react to routing, or clean up resources.
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"));
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.
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");
});
}
}