Hi
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.
@SpringComponent
public class UsersView extends VerticalLayout {
@Inject
private UserDao userDao;
@PostConstruct
void init() {
Label countLabel = new Label(new AbstractProperty<String>() {
@Override
public String getValue() {
return String.valueOf(userDao.count());
}
@Override
public void setValue(String newValue) throws ReadOnlyException {
}
@Override
public Class<? extends String> getType() {
return String.class;
}
});
addComponent(countLabel);
final int pageSize = 10;
MTable<User> mTable = new MTable<>(User.class,
i -> {
return userDao.list(1, pageSize);
},
() -> (int) userDao.count() , pageSize
)
.withProperties("id", "name")
;
mTable.refreshRows();
mTable.setSizeFull();
addComponent(mTable);
}
}
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