CDI MVP
Lightweight MVP pattern for Vaadin CDI projects
MVP (model-view-presenter) is an emphasized pattern for larger Vaadin applications. CDI MVP provides a lightweight approach to building a foundation for your front-end layer with Vaadin and MVP.
A good example on how to use CDI MVP in a Vaadin project can be found in the links section.
The add-on can only be used in Vaadin CDI enabled projects.
Sample code
@ViewInterface(ListView.class) public class ListPresenter extends AbstractMVPPresenter<ListView> { @Inject private PersonDAOBean personDAO; public static final String EDIT_PERSON = "list_presenter_edit_person"; public static final String SAVE_PERSON = "list_presenter_save_person"; protected void editPerson( @Observes @CDIEvent(EDIT_PERSON) final ParameterDTO parameters) { view.editSelectedPerson(); } protected void savePerson( @Observes @CDIEvent(SAVE_PERSON) final ParameterDTO parameters) { Person person = parameters.getPrimaryParameter(Person.class); if (person.isPersistent()) { personDAO.update(person); } else { person = personDAO.persist(person); view.addContactToList(person); } view.selectPerson(person); } }
... editButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { /* * Clicking the edit button only fires an event and nothing * more. The presenter which observes the event will decide what * happens next. */ fireViewEvent(ListPresenter.EDIT_PERSON, null); } }); ...
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
CDI 1.1 supported
- Released
- 2014-01-04
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.0+
- Browser
- Browser Independent