Reputation: 417
I am new to vaadin framework. I am trying to refresh the embedded page when I click on a button of a vaadin component.
I found that we can use Refresher add-on but I am quiet confused how to use it.
any suggestions ?
Upvotes: 1
Views: 3648
Reputation: 542
I had problems adding the refresher to the layout
The method addComponent(Component) in the type AbstractOrderedLayout is not applicable for the arguments (Refresher)
Here's an example code of I used:
public class RefresherDemo extends UI {
Refresher refresher;
Label timeLabel;
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
timeLabel = new Label(getTime());
refresher = new Refresher();
refresher.setRefreshInterval(500);
refresher.addListener(new RefreshListener(){
@Override
public void refresh(Refresher source) {
timeLabel.setValue(getTime());
}
});
addExtension(refresher);
layout.addComponent(timeLabel);
}
public String getTime(){
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
String d = dateFormat.format(date);
return d;
}
}
Upvotes: 0
Reputation: 825
I also recommend you to use the refresher addon. I use it for my application as well and it's working perfect.
As a little example:
//Create the Refresher
final Refresher refresher = new Refresher();
//time period in ms when the Refresher shell call the attached listener
refresher.setRefreshInterval(5000);
//listener that gets called every 5000ms in this example
refresher.addListener(new MyRefresherListener());
//add the Refresher component to your layout
myLayout.addComponent(refresher);
A implementation of the listener can look like the following:
import com.github.wolfie.refresher.Refresher;
import com.github.wolfie.refresher.Refresher.RefreshListener;
public class MyRefreshListener implements RefreshListener {
private static final long serialVersionUID = 1L;
@Override
public void refresh(final Refresher source) {
System.out.println("I am getting refreshed");
// add the refresh page of your application logic here
// e.g. the same code you use for changing views when a button click is happening
}
}
Upvotes: 4