Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Adding Spring support in dashboard application
Hi all,
I'm a newbie of Vaadin and I'm trying to integrate Spring in Vaadin Dashboard application.
I've modified views and UI as shown here below.
@UIScope
@SpringView(name = TransactionsView.VIEW_NAME)
public class TransactionsView extends VerticalLayout implements View {
public static final String VIEW_NAME = "transaction";
@Autowired
Greeter greeterService;
@PostConstruct
void init() {
// build layout
}
@Override
public void enter(ViewChangeEvent event) {
logger.debug("+++ enter +++");
}
@Theme("dashboard")
@Widgetset("com.vaadin.demo.dashboard.DashboardWidgetSet")
@Title("QuickTickets Dashboard")
@SuppressWarnings("serial")
@SpringUI
@SpringViewDisplay
public final class DashboardUI extends UI implements ViewDisplay{
Everything works fine until I click on Transactions view button:
the problem is that I got a nullpointerexception on injected bean because init method with PostCostruct annotation (where beans is used) hasn't been called ...
It seems that in DashboradNavigator views have already been created before ViewProvider construction, so that init method in view is not called.
Could it be the right reason for that issue?
Thanks for help.
// A dedicated view provider is added for each separate view type
for (final FisiomanagerViewType viewType : FisiomanagerViewType.values()) {
ViewProvider viewProvider = new ClassBasedViewProvider(
viewType.getViewName(), viewType.getViewClass()) {
// This field caches an already initialized view instance if the
// view should be cached (stateful views).
private View cachedInstance;
@Override
public View getView(final String viewName) {
View result = null;
if (viewType.getViewName().equals(viewName)) {
if (viewType.isStateful()) {
// Stateful views get lazily instantiated
if (cachedInstance == null) {
cachedInstance = super.getView(viewType
.getViewName());
}
result = cachedInstance;
} else {
// Non-stateful views get instantiated every time
// they're navigated to
result = super.getView(viewType.getViewName());
}
}
return result;
}
};
if (viewType == ERROR_VIEW) {
errorViewProvider = viewProvider;
}
addProvider(viewProvider);
}