Vaadin and CDI - can't use SessionScoped beans

Hi Everybody,

I’m trying make a Vaadin application with JEE6. I started from that link http://vaadin.com/wiki/-/wiki/Main/Creating%20JEE6%20Vaadin%20Applications (Option 2). Everything works fine. Next I added some views to my application. For example:


public class StudentsManagerView extends VerticalLayout implements AbstractView
{
    @Inject
    private AccountManagerFacade accountManager;

//fields and methods
}

(AbstractView is just empty interface.)
And inject it to Application:


@SessionScoped
public class MyApp extends Application {
    @Inject private StudentManagerView studentManager;  

     
    @Override
    public void init() {}
}

Evertything works there i have reference to EJB in my view. But, studentManager object is built at application start. Now I have 20 different views which i switch from menu. So i don’t want to build them on startup. So, I used Instance<>.


@Inject private Instance<StudentManagerView> studentManager;

and get instance from studentManager.get().
Yes, works fine now, constructors(init() methods with @PostConstruct annotation to be clear) are called only at first use of view. But, in this place i lost most important think. Always when I want to show view:


splitPanel.setSecondComponent(studentManager.get());

server takes me new instantion of class, so I loose previous state of view.
Injected object(studentManager) should have same scope which “parent” object(myApp) - session scope, but it haven’t when I’m using Instance<>(object is seesion scope with pure @Inject without Instance<>). I tried to use javax.inject.Singleton anntotation with StudentManagerView and it’s work, I have always one instance of object, but it’s shared between all application instances. So, I thought @SessionScoped with StudentManagerView should be that, but there is the problem. I have deploy time exception:


SEVERE: Exception while loading the app : WELD-001437 Normal scoped bean class com.vaadin.ui.AbstractComponent is not proxyable because the type is final or it contains a final method public final java.lang.String com.vaadin.ui.AbstractComponent.getTag().

there in AbstractComponent which I have to use, because Layouts extends it, two final method, which one is depreciated.

Now my question, maybe somebody have some workaround solution for my problem.

Sorry for my bad English, I hope somebody will understand it…

Best Regards,
Artur

Hi Artur,
I am facing the same problem you are having here. From my research i found that the problem is due to the fact that CustomComponent class in Vaadin uses Final keyword which break the ability of the CDI container to create proxies of the class. I guess this is rather a show stopper.

I am trying to play abit with the source code to figure out will the removal of the final modifiers could truly fix this problem.

If you were able to solve this problem i appreciate your advise.

Regards,

Well i have built Vaadin from source removing final modifiers from CustomComponent and its parents and now it seems that Glassfish Container does not complain about the aforementioned error. I guess the problem you have with AbstractView is similar to mine. You could do the same.

However, I do not know whether such a change would cause problems or break something that Vaadin team meant to integrate into the code itself.

I hope someone from Vaadin development team would enlighten me regarding this point.

Thanks

I am facing the problem too. It occur when I use 6.6.3 version

Will fix at Vaadin 6.7.

Please wait :grin: