无论我尝试什么,Vaadin Table都不会更新 [英] Vaadin Table does not update no matter what I try

查看:285
本文介绍了无论我尝试什么,Vaadin Table都不会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Vaadin(6.7.4),并且此表(它位于模式窗口中)不会更新视图。

首先它是用生成的列创建的,但我读到它有更新表的问题,所以我切换回普通表,但仍然没有刷新。



更新数据被调用按面板上的按钮点击事件

  final Table table = new Table(); 
final IndexedContainer ic = new IndexedContainer();

public createTable(){
table.setImmediate(true);
table.setEnabled(true);
ic.addContainerProperty(Name,String.class,null);
ic.addContainerProperty(Edit,Button.class,null);
ic.addContainerProperty(Delete,Button.class,null);
table.setContainerDataSource(ic);
}

public void addItems(Table table){
for(String s:createdNames){
ic.addItem(s);
ic.getItem(s).getItemProperty(Name)。setValue(s);
ic.getItem(s).getItemProperty(Edit)。setValue(Edit);
ic.getItem(s).getItemProperty(Delete)。setValue(Delete);



$ b public void updateData(){
IndexedContainer c =(IndexedContainer)table.getContainerDataSource();
c.removeAllItems();
c.addItem(myname);
c.getContainerProperty(myname,Name)。setValue(Mr.X);
table.setContainerDataSource(c);
table.refreshRowCache();
table.requestRepaint();
System.out.println(查看输出,但没有更新表);
}

编辑:原来问题不是关于这段代码,而是这个类被实例化2次,所以我有不同的例子;这是一个我正在更新和我看到的。

解决方案

这是一个完整的Vaadin应用程序:

  public class TableTest extends Application {
final Table table = new Table();
final IndexedContainer ic = new IndexedContainer();

@Override
public void init(){
setMainWindow(new Window(Window));
createTable();
getMainWindow()。addComponent(table);
getMainWindow()。addComponent(
new Button(Click me,new Button.ClickListener(){
public void buttonClick(ClickEvent event){
updateData();
}
}));
}

public void createTable(){
table.setImmediate(true);
table.setEnabled(true);
ic.addContainerProperty(Name,String.class,null);
ic.addContainerProperty(Edit,Button.class,null);
ic.addContainerProperty(Delete,Button.class,null);
table.setContainerDataSource(ic);
}

public void updateData(){
ic.removeAllItems();
ic.addItem(myname);
ic.getContainerProperty(myname,Name)。setValue(Mr.X);
System.out.println(查看输出,但没有更新表);


$ / code>

看来问题出在代码中的其他地方。顺便说一句,将来你应该从头开始创建一个全新的应用程序来隔离问题并验证它是你认为它的地方。


I use Vaadin (6.7.4) and this table (it is on a modal window) does not update the view.

First it was created with generated columns, but I read that it has problems with table update, so I switched back to normal table, but still no refresh.

Updatedata is called by button click event on the panel

final Table table = new Table();
final IndexedContainer ic=new IndexedContainer();

public createTable(){
    table.setImmediate(true);   
    table.setEnabled(true); 
    ic.addContainerProperty("Name", String.class,  null);
    ic.addContainerProperty("Edit", Button.class, null);
    ic.addContainerProperty("Delete", Button.class,  null);
    table.setContainerDataSource(ic);
}

public void addItems(Table table) {
    for (String s : createdNames) {
        ic.addItem(s);
        ic.getItem(s).getItemProperty("Name").setValue(s);
        ic.getItem(s).getItemProperty("Edit").setValue("Edit");
        ic.getItem(s).getItemProperty("Delete").setValue("Delete");
    }

}

public void updateData() {      
    IndexedContainer c=(IndexedContainer) table.getContainerDataSource();
    c.removeAllItems();
    c.addItem("myname");
    c.getContainerProperty("myname", "Name").setValue("Mr.X");
    table.setContainerDataSource(c);
    table.refreshRowCache();
    table.requestRepaint();
    System.out.println("see the output but no update on table");
}

Edit: turned out problem is not about this code, but this class was instantiated 2 times, so I had different instances; the one i am updating and the one I see.

解决方案

Here is a complete Vaadin application that works:

public class TableTest extends Application {
final Table table = new Table();
final IndexedContainer ic = new IndexedContainer();

@Override
public void init() {
    setMainWindow(new Window("Window"));
    createTable();
    getMainWindow().addComponent(table);
    getMainWindow().addComponent(
            new Button("Click me", new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    updateData();
                }
            }));
}

public void createTable() {
    table.setImmediate(true);
    table.setEnabled(true);
    ic.addContainerProperty("Name", String.class, null);
    ic.addContainerProperty("Edit", Button.class, null);
    ic.addContainerProperty("Delete", Button.class, null);
    table.setContainerDataSource(ic);
}

public void updateData() {
    ic.removeAllItems();
    ic.addItem("myname");
    ic.getContainerProperty("myname", "Name").setValue("Mr.X");
    System.out.println("see the output but no update on table");
}
}

It seems that the problem is somewhere else in your code. By the way, in the future you should create a completely new application from scratch to isolate the problem and validate that it is where you think it is.

这篇关于无论我尝试什么,Vaadin Table都不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆