Hi,
i’am new to vaadin and i use vaadin with the cdi extention. I created a View with some Input elements.
On buttonclick i open a subwindow where the user can select some things. This things need to be transfered to the forms of the view. I want to transport the selection via an event back to the view. But the Observer Method never gets called.
This Feature is essential for my application because i want to decouple the window from the view to use the window on many places inside this and other applications.
Here is some code of what i try to do.
MainView
[code] @CDIView(“search”) @UIScoped
public class Search extends VerticalLayout implements View{
@UIScoped
public class SearchWindow extends Window{
@Inject
javax.enterprise.event.Event<SelectionEvent> selectEvent;
//call selectEvent.fire(event); somewhere
}
The listenToSelection Method never gets called. Any idea how to fix this problem? Has it something to do with the different Scopes of the View and the Window?
Try removing the @UIScoped annotation in your
Search class (the view implementation). With this change, the view won’t retain its state when the user navigates to another view (it will have view scope).
I tested it and it works in views with @UIScoped when the observer method is not conditional (without
notifyObserver = Reception.IF_EXISTS or with
notifyObserver = Reception.ALWAYS ). So, the problem might be related to scopes.
Hi,
thank you for the reply and sorry for the long delay. I was out for holiday
To the problem. I added
notifyObserver = Reception.ALWAYS to my observer and you are right, the view observer gets the event. But in the wrong instance of the view. It seems like it creates a new instance of the view and sets the values.
I have a second window in the same view with the same task to let the user select some things and transfer it on button click to the main view. Interestingly those windows seem to share the same Instance of the view but not on the “right” instance.
I’d avoid coupling the UI with my data and use a SessingScoped bean for passing data back and forth. My two cents. I personally like to keep the view layer as decoupled as possible