我是vaadin框架的新手。当我点击vaadin组件的按钮时,我正在尝试刷新嵌入的页面。
我发现我们可以使用Refresher附加组件,但我很困惑如何使用它。
有什么建议吗?
答案 0 :(得分:4)
我还建议您使用复习插件。我也将它用于我的应用程序,它的工作完美。
作为一个小例子:
//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);
侦听器的实现可能如下所示:
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
}
}
答案 1 :(得分:0)
我在将更新添加到布局
时遇到了问题AbstractOrderedLayout类型中的方法addComponent(Component)不适用于参数(Refresher)
这是我使用的示例代码:
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;
}
}