Is it possible to use @Push together with the CDI Observer Pattern?
When I try to listen to an event a new UI is created.
My UI:
@Theme("powel")
@CDIUI(value="taskboard")
@SessionScoped
@Push
@Slf4j
public class TaskboardUI extends UI {
@Inject
private Instance<Navigator> navigator;
@Override
protected void init(final VaadinRequest request) {
log.info("Initialize navigator.");
navigator.get();
}
}
The Navigator:
[code]
@UIScoped
public class ComponentFactory {
@Produces
public final Navigator getNavigator(final UI ui, final CDIViewProvider viewprovider) {
val navigator = new Navigator(ui, ui);
navigator.addProvider(viewprovider);
return navigator;
}
}
[/code]The Event Producer:
@Stateless(mappedName = "ejb/MessageRepository")
@LocalBean
@Data
public class MessageRepository {
@Inject
private Event<NewMessageGroupEvent> newMessageGroupEvents;
public void addMessageGroup(final MessageGroup messageGroup) {
messageGroups.add(messageGroup);
NewMessageGroupEvent event = new NewMessageGroupEvent(messageGroup);
newMessageGroupEvents.fire(event);
}
}
The View and Receiver:
[code]
@CDIView(“”)
@Slf4j
public class MainView extends VerticalLayout implements View {
@Inject
private MessagePanelFactory messagePanelProvider;
public void addMessageGroup(final MessageGroup messageGroup) {
this.addComponent(messagePanelProvider.getNewInstance(messageGroup));
}
void listenToNewMessageGroup(@Observes final NewMessageGroupEvent event) {
log.info("Received 'New message event'.");
UI.getCurrent().access(new Runnable() {
@Override
public void run() {
addMessageGroup(event.getMessageGroup());
}
});
}
}
@Override
public final void enter(final ViewChangeEvent event) {
}
}
[/code]The UI is not changing at all. Is there an example available for this? Or what am I doing wrong?
Kind regards
Christian