CDI Utils
Utilities for CDI/Vaadin applications
PROJECT DISCONTINUED! Replaced by the official Vaadin CDI plugin and CDI Properties & CDI MVP add-ons
CDI is a JavaEE standard that consists of two fundamental parts: It allows you to bind bean instances to contexts with well-defined life-cycles and inject instances to beans in a type-safe way.
CDI Utils add-on provides some utilities for CDI/Vaadin applications: -Custom CDI Context for Vaadin -Lightweight MVP framework -Producers for declaratively defined Vaadin components (@Preconfigured -annotation) -Built in i18n of @Preconfigured components
Quick start (CDI Utils 2):
- Add empty beans.xml -file (CDI marker file) to your project under WEB-INF dir
- Add cdi-utils*.jar to your project
- Annotate your UI with @UIScoped
- Give the Vaadin servlet an init parameter "UIProvider" with the value "org.vaadin.virkki.cdiutils.application.CdiUIProvider"
- Deploy to JavaEE/Web profile -compatible container
Quick start (CDI Utils 1):
- Add empty beans.xml -file (CDI marker file) to your project under WEB-INF dir
- Add cdiutils*.jar to your project
- Create your Application class by extending AbstractCdiApplication
- Use CdiApplicationServlet instead of the normal ApplicationServlet
- Deploy to JavaEE/Web profile -compatible container (CDI apps can also be run on servlet containers etc. but some further configuration is required)
See the example projects at: CDI Utils 2: https://github.com/tomivirkki/cdiutils-addressbook/tree/vaadin7 CDI Utils 1: https://github.com/tomivirkki/cdiutils-addressbook
Sample code
public class CUDemoApplication extends AbstractCdiApplication { @WebServlet(urlPatterns = "/*", initParams = @WebInitParam(name = "application", value = "org.vaadin.virkki.cdiutils.example.CUDemoApplication")) public static class CUDemoApplicationServlet extends CdiApplicationServlet { } @Inject private Instance<MainViewImpl> mainView; @Override public void init() { setMainWindow(new Window("demo")); getMainWindow().addComponent(mainView.get()); mainView.get().openView(); } }
public class CustomersViewImpl extends AbstractView implements CustomersView { @Inject @Preconfigured(sizeFull = true) private VerticalLayout mainLayout; @Inject @Preconfigured(caption = "Some data", width = 400, widthUnits = UNITS_PIXELS, enabled = false) private TextArea textArea; @Inject @Preconfigured(captionKey = "update-button-caption", styleName = Reindeer.BUTTON_LINK) private Button button; @Override protected void initView() { setCompositionRoot(mainLayout); mainLayout.addComponent(textArea); button.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { // The event is observed in presenter fireViewEvent("update", this); } }); mainLayout.addComponent(button); } @Override public void updateTextContent(String content) { textArea.setValue(content); } }
@ViewInterface(CustomersView.class) public class CustomersPresenter extends AbstractPresenter<CustomersView> { // Access your backend in the presenter @EJB private CustomersBean customersBean; @Override protected void initPresenter() {} @Override public void viewOpened() { view.updateTextContent(null); } public void updateRequested(@Observes @CDIEvent( "update") ParameterDTO param) { view.updateTextContent("Updated content"); } }
@UIScoped public class AddressBookUI extends UI { @WebServlet(urlPatterns = "/*", initParams = { @WebInitParam(name = "UI", value = "org.vaadin.virkki.cdiutils.addressbook.AddressBookUI"), @WebInitParam(name = "UIProvider", value = "org.vaadin.virkki.cdiutils.application.CdiUIProvider")}) public static class AddressBookApplicationServlet extends VaadinServlet { } @Inject private MainViewImpl mainView; @Override protected void init(final VaadinRequest request) { setContent(mainView); mainView.openView(); } }
Links
- Source Code (CDI Utils 2)
- CenterDevice project
- Embedded Jetty, Vaadin and Weld
- Source Code (CDI Utils 1)
- Example project (CDI Utils 2)
- Example project (CDI Utils 1)
- Discussion Forum
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
- Released
- 2013-03-03
- Maturity
- STABLE
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.0+
- Vaadin 6.7+ in 1.2.1
- Browser
- Browser Independent