Presenters orchestrate lifecycle, routing, slots, events, security, and navigation confirmation around a view. The processor generates the implementation and binds the injected view.
@BrixPresenter
@BrixRoute("dashboard")
@BrixSlot(BrixSlots.BRIX_BODY_SLOT)
public class DashboardPresenter extends Presenter<DashboardView> {
@Override
protected void onRevealed() {
view.showMessage("Hello, Brix!");
}
}
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.
public class ConfirmingView extends BrixView<Element, FormHandlers>
implements CanConfirmNavigation {
private boolean dirty;
@Override public boolean isConfirmNavigation() { return dirty; }
@Override
public void confirmNavigation(ConfirmNavigationHandlers handlers) {
if (window.confirm("Discard changes?")) handlers.onConfirmed();
else handlers.onCanceled();
}
}
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.
@BrixPresenter
@BrixRoute("details/:id")
@BrixSlot("content-slot")
public class DetailsPresenter extends ChildPresenter<DashboardPresenter, DetailsView> {
@PathParameter("id") String id;
@Override
protected void onActivated() {
view.loadDetails(id);
}
@Override
public void onBindParent(DashboardPresenter parent) {
view.setHeader(parent.getHeaderTitle());
}
}