Bambi MVVM
A lightweight annotation-driven Model View ViewModel (MVVM) library for building clean and testable Vaadin applications.
Bambi is a lightweight MVVM add-on for Vaadin web applications. Bambi uses a declarative style annotation-driven approach to UI binding. The framework attempts to adhere to basic MVVM principles and allows users to develop expressive UI with highly testable view models. One of the primary design goals of the Bambi framework is to enable the creation of minimalist, and highly readable code whilst not impeding the ability to deliver rich client user interfaces.
Please note that this is a very early alpha release and is yet to contain the full feature set intended. The project is open source and contributors are welcomed.
Future releases are intended to include:
- Additional binding support @EnabledIf, @ViewBound, etc.
- View model annotations @OnBind, @OnUnbind.
- Container managed views and view models with Spring integration for first-class dependency injection.
- Testing utilities to help validate UI against associated view models.
- Annotation processor to automatically validated bindings at compile time.
- All important unit test coverage.
I've republished the library with the now correct project name.
-Michael
Sample code
@View(model = AddressBookViewModel.class) public class AddressBookView extends CustomComponent implements Handler { private static final long serialVersionUID = 1L; @ActionBound(to = "addAddress") private final Button addButton = new Button("New Address"); @ActionBound(to = "removeAddress") private final Button removeButton = new Button("Remove Address"); @PropertyBound(to = "selected") private final AddressBookForm form = new AddressBookForm(); @ContainerBound(to = "addresses", columns = { NAME_PROPERTY, SURNAME_PROPERTY, LINE1_PROPERTY, LINE2_PROPERTY, CITY_PROPERTY, STATE_PROPERTY, AREACODE_PROPERTY, COUNTRY_PROPERTY }) @ValueChangeBound(to = "selectAddress") private final Table table = new Table(); private final Action commitAction = new ShortcutAction("ENTER", ShortcutAction.KeyCode.ENTER, null); public AddressBookView() { VerticalSplitPanel splitPanel = new VerticalSplitPanel(); VerticalLayout topLayout = new VerticalLayout(); HorizontalLayout buttonPanel = new HorizontalLayout(); buttonPanel.setSpacing(true); buttonPanel.setMargin(true); buttonPanel.addComponent(addButton); buttonPanel.addComponent(removeButton); topLayout.addComponent(buttonPanel); topLayout.addComponent(table); topLayout.setExpandRatio(table, 1.0f); topLayout.setSizeFull(); table.setSizeFull(); table.setSelectable(true); table.setMultiSelect(false); table.setImmediate(true); splitPanel.setFirstComponent(topLayout); splitPanel.setSecondComponent(form); splitPanel.setSplitPosition(60.0f, UNITS_PERCENTAGE); setCompositionRoot(splitPanel); setSizeFull(); } ...
public class AddressBookViewModel implements Serializable { private static final long serialVersionUID = 1L; public final Container addresses = new BeanItemContainer<Address>(Address.class); public final ObjectProperty<BeanItem> selected = new ObjectProperty<BeanItem>(null, BeanItem.class); public void selectAddress(Property.ValueChangeEvent event) { Table table = (Table)event.getProperty(); Item selectedItem = table.getItem(table.getValue()); selected.setValue(selectedItem); } public void addAddress(Button.ClickEvent event) { Address newAddress = new Address(); Item item = addresses.addItem(newAddress); selected.setValue(item); event.getComponent().getWindow().showNotification("Address Added",TYPE_HUMANIZED_MESSAGE); } public void removeAddress(Button.ClickEvent event) { BeanItem item = (BeanItem)selected.getValue(); Address address = (Address)item.getBean(); if(addresses.removeItem(address)) { event.getComponent().getWindow().showNotification("Address Removed", TYPE_HUMANIZED_MESSAGE); } } }
public class AddressBook extends Application { private static final long serialVersionUID = 1L; private Window window; /** {@inheritDoc} */ @Override public void init() { window = new Window("Bambi Demo Application - Address Book"); ViewContainer<AddressBookView> view = new AnnotatedViewFactory().materialize(AddressBookView.class); window.setContent(view); setMainWindow(window); } }
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
- Added manifest information to enable publishing to Vaadin Maven repository.
- Released
- 2012-09-10
- Maturity
- EXPERIMENTAL
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 6.8+
- Browser
- Browser Independent
Bambi MVVM - Vaadin Add-on Directory
A lightweight annotation-driven Model View ViewModel (MVVM) library for building clean and testable Vaadin applications.Author Homepage
Online Demo
Issue Tracker
Bambi MVVM version 1.0.0-alpha2
- Added ViewFactory implementation for simple view materialization.
- Added ability to specify columns on @ContainerBound Table elements.
- Updated demo application to run on Google App Engine
* To run locally use mvn gae:run from demo module.
Bambi MVVM version 1.0.0-alpha3
- Added manifest information to enable publishing to Vaadin Maven repository.