1

我是 vaadin 框架的新手。当我单击 vaadin 组件的按钮时,我正在尝试刷新嵌入页面。

我发现我们可以使用 Refresher 插件,但我很困惑如何使用它。

有什么建议么 ?

4

2 回答 2

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
    }
}
于 2012-08-19T14:20:12.307 回答
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;
    }

}
于 2013-03-01T08:25:04.237 回答