Skip to content
Ahmad K. Bawaneh edited this page Nov 7, 2021 · 10 revisions

Views in domino-mvp are the UI part of the module, a view defines what kind of content we need to render in the application, we have seen that ViewBaseClientPresenter sub-classes will define a generic type that is of type ? extends View, all views in Domino-mvp must extend from the interface View, presenters should never know about the view implementation details and for that views from the presenter perspective are just interfaces that play the role of a contract between the presenter and the view actual implementation, the presenter will call methods defined in the interface to manipulate the view without understanding what kind of UI components or how the view will handle those calls, the framework during the presenter life-cycle will create a view instance from its implementation and inject it into the presenter.

The View interface itself in Domino-mvp is just a marker interface and does not specify any methods, a more useful interface is ContentView which from the name provide a content, most of the time this is the interface we will be using, the ContentView provides a single element that represent the root element of the view which will be the element that we attach to the application UI when the view is revealed, example :

import org.dominokit.domino.api.client.mvp.view.ContentView;

public interface BookView extends ContentView {
    void setBookTitle(String title);
}

an implementation of this interface should be annotated with @UiView specifying to which presenter it belongs. example :

import elemental2.dom.HTMLDivElement;
import org.dominokit.domino.api.client.annotations.UiView;
import org.dominokit.domino.api.shared.extension.Content;
import org.dominokit.domino.ui.utils.DominoElement;
import org.dominokit.samples.shell.client.presenters.BookProxy;
import org.dominokit.samples.shell.client.views.PersonView;

@UiView(presentable = BookProxy.class)
public class BookViewImpl implements BookView {

    private DominoElement<HTMLDivElement> root = DominoElement.div();

    @Override
    public void setBookTitle(String title) {
        root.setTextContent(title);
    }

    @Override
    public Content getContent() {
        return (Content<HTMLDivElement>) () -> root.element();
    }
}

Now a presenter can use such view like the following example :

@PresenterProxy
@AutoRoute(token = "books/:title")
public class BookProxy extends ViewBaseClientPresenter<BookView> {

    @PathParameter
    String title;

    @OnReveal
    public void setBookTitle(){
        view.setBookTitle(title);
    }
}

@UiView presentable argument takes one or more presenters, as we can link the same view with more than one presenter, each presenter will have its own instance of the view