I looked at those and used them to get started but they only show how to get the Application class annotated. They don't show annotating any other UI classes. The forums also mention has this is currently an issue with CDI and suggest accessing all context beans through the application class. I'm wondering why it has to be that way and you can't just @Inject into UI classes directly.
Ask them to come over here and talk about it if they think there is some
issue with CDI
IIRC, if you instantiate a bean using
newkeyword, it simply won't be managed, thus can't use @Inject, be intercepted, etc. When building your layout you should inject your component into the Application and then it should be managed.
... I saw this post and decided to answer my experience.
Since Vaadin is processed inside a Servlet, if you follow SEAM instructions to context management for custom servlets, everything will work fine:
1. Declare the seam filter in the web.xml
<filter> <filter-name>Seam Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class> </filter> <filter-mapping> <filter-name>Seam Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
2. Declare your Vaadin application Servlet (as described in Vaadin book)
3. in components.xml, enable the context filter
4. Inside Vaadin servlet, use SEAM API, like Component and Contexts classes
For me it's working perfectly.
For CDI, you can also use the method described in the Vaadin wiki :
(Option 2: Use CDI)
That methods subclasses the Vaadin servlet so it's initialized by CDI using @SessionScoped, as well as getting your Vaadin application via @Inject)
I'm not sure which one is better architecturally, but that method has no dependency on Seam or any other third-party library at all.
Hi Ricardo, your solution is working for me too! Thx for the
Nevertheless, something is still missing on my side. How did you manage transactions ?
Thx in advance.
Wouldn't Vaadin be required to have a META-INF/beans.xml in its main jar file if its artifacts were to be considered for injection? Just testing my assumptions. I am pretty sure their jar file has no such file. Apologies if this is all painfully obvious or stupid.