I just finished watching the above titled youtube video with Matti and Geertjan, which I thoroughly enjoyed, but I have been left with an unanswered question that I just can’t seem to find a solution to. I have basically recreated the steps that Matti took to build a Vaadin application by adding entity classes from a database, and creating session beans for those entity classes.
In the view where I would like to present the data, I have injected the facade where the data should be available from, and I notice that all of the code that Matti adds to display the data is added to a function called initComponent(), which is annotated with the @PostConstruct annotation (which makes perfect sense), however, I can’t seem to find where the initComponent function gets called from. It doesn’t seem to be an overridden method. If I try to call it explicitly from the enter() method of the class (overridden from the View), I get the dreaded NPE for the injected facade.
I must be missing something very basic. I’m deploying to glassfish servers (version 3.2 and 4.0 - works on neither).
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.lamtec.vaadintest;
import com.lamtec.vaadintest.entity.Arcust;
import com.lamtec.vaadintest.entity.ejb.ArcustFacade;
import com.vaadin.cdi.CDIView;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.vaadin.maddon.fields.MTable;
import org.vaadin.maddon.layouts.MVerticalLayout;
/**
*
* @author penrosekevin
*/
@CDIView("Arcust")
public class ArcustTableView extends MVerticalLayout implements View {
private static final long serialVersionUID = 1L;
@Inject
ArcustFacade af;
public ArcustTableView() {
addComponent(new Label("Arcust"));
}
@PostConstruct
public void initComponent() {
List<Arcust> findAll = af.findAll();
MTable<Arcust> mtable = new MTable<>(Arcust.class);
mtable.setBeans(findAll);
addComponent(mtable);
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
Notification.show("In ArcustTableView");
// initComponent();
}
}
Any help is appreciated.