How to ensure load from db when rendering ?

I am new to Vaadin for 2 days. I am blocked by a simple question : How to ensure load from db when rendering ?
In my UI class , I create a HorizontalSplitPanel . When user clicks the left tree , right panel renders correspondent view.
The problem is , the right panel caches the data loaded from DB. It cannot reflects the latest state in DB.

The right panel contains two component . countLabel , and mTable .
countLabel shows how many users in DB . and mTable loads/displays them.

public class UsersView extends VerticalLayout {

  private UserDao userDao;

  void init() {
    Label countLabel = new Label(new AbstractProperty<String>() {
      public String getValue() {
        return String.valueOf(userDao.count());

      public void setValue(String newValue) throws ReadOnlyException {


      public Class<? extends String> getType() {
        return String.class;


    final int pageSize = 10;
    MTable<User> mTable = new MTable<>(User.class,
      i -> {
        return userDao.list(1, pageSize);
      () -> (int) userDao.count() ,  pageSize
      .withProperties("id", "name")

I want Vaadin to display correct countLabel (user count) and userList (mTable) upon each rendering.
But it seems only countLabel works correctly (But I feel it is tedious , anyway to improve/shorten it ?) .

The mTable is cached forever.

If the user navigates to other component and back (by clicking the left tree node) , if DB state changes (user added or removed) , countLabel shows correctly , but mTable doesn’t reflect the true state.

Even the user refresh the browser , the mTable still displays stale data.

How to fix such issue ?

(The UsersView is injected to my UI class )

Environment :
spring-boot 1.3.3
vaadin-spring-boot-starter : 1.0.0
viritin : 1.47

I solve the problem by introducing another customized interface : Reloadable

public interface Reloadable { void reload(); } And my views implement this interface :

public class TeachersView extends VerticalLayout implements Reloadable {

  private TeacherDao teacherDao;

  private final static int PAGESIZE = 10;

  private MTable<Teacher> mTable = new MTable<>(Teacher.class);

  public void init() {
    // other mTable settings ...


  public void reload() {
    mTable.setBeans(new SortableLazyList<>(
      sortablePagingProvider ,
      () -> (int) teacherDao.count() ,

  private SortableLazyList.SortablePagingProvider<Teacher> sortablePagingProvider =
    (firstRow, asc, sortProperty) -> {"teacherDao.findAll ...");
      return teacherDao.findAll(
        new PageRequest(
          firstRow / PAGESIZE, PAGESIZE,
          asc ? Sort.Direction.ASC : Sort.Direction.DESC,
          sortProperty == null ? "id" : sortProperty

And in the UI class :

@SpringUI(path = "/ui")
public class VaadinUI extends UI {

  private TeachersView teachersView;

  // other injected views skipped

  protected void init(VaadinRequest vaadinRequest) {
    Panel panel = new Panel("Admin Panel");

    HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
    splitPanel.setSplitPosition(15, Unit.PERCENTAGE);

    Tree tree = new Tree("Menu");

    Label home = new Label("Home");

    Map<String, Component> map = new HashMap<>();
    map.put("Teachers", teachersView);
    // other views

    map.forEach((k, v) -> tree.addItem(k));

    tree.addItemClickListener(event -> {
      Component view = map.get(event.getItemId());
      if (view instanceof Reloadable) {
        Reloadable reloadable = (Reloadable) view;


  } // init()


It works !
But I don’t know if it the proper or
way achieving this ?
Is it the
way ? Or anything built-in I can follow ? Thanks.