GWT-celltable
我的单元格表中的一列没有填充任何内容,这是一个问题。以下是我的代码:GWT-celltable,gwt,Gwt,我的单元格表中的一列没有填充任何内容,这是一个问题。以下是我的代码: public class CellTableExample implements EntryPoint { private static class Contact { private String address; private String name; private String phone=""; public Contact(String name, String addre
public class CellTableExample implements EntryPoint {
private static class Contact
{
private String address;
private String name;
private String phone="";
public Contact(String name, String address, String phone) {
super();
this.address = address;
this.name = name;
this.phone=getPhoneNumber(name);
}
}
public String getPhoneNumber(String name)
{
String pNum="";
SQLRunnerAsync service = (SQLRunnerAsync) GWT.create(SQLRunner.class);
AsyncCallback<String> callback = new AsyncCallback<String>()
{
@Override
public void onFailure(Throwable caught)
{
}
@Override
public void onSuccess(ArrayList<String[]> result)
{
pNum=reuslt;
}
};
service.findPhoneNum(name,callback);
return pNum;
}
// The list of data to display.
private static List<Contact> CONTACTS = Arrays.asList(
new Contact("John", "123 Fourth Road asdf asdf asdfasdf"),
new Contact("Mary", "222 Lancer Lane")
);
@Override
public void onModuleLoad() {
CellTable<Contact> table = new CellTable<Contact>();
SQLRunnerAsync service = (SQLRunnerAsync) GWT.create(SQLRunner.class);
AsyncCallback<ArrayList<String[]>> callback = new AsyncCallback<ArrayList<String[]>>()
{
@Override
public void onFailure(Throwable caught)
{
}
@Override
public void onSuccess(ArrayList<String[]> result)
{
compFlexTable.setPageSize(result.size());
Contact[] contactArr = new Contact[result.size()];
for(int i=0;i<result.size();i++)
{
String [] temp = result.get(i);
String name=temp[0];//name
String address=temp[1];//address
contactArr[i]=new Component1(name,address);
}
COMPONENT=Arrays.asList(compArray);
//address column
TextColumn<Contact> addressColumn = new TextColumn<Contact>(){
@Override
public String getValue(Contact contact) {
return contact.address;
}
};
//name column
TextColumn<Contact> nameColumn = new TextColumn<Contact>(){
@Override
public String getValue(Contact contact) {
return contact.name;
}
};
//name column
TextColumn<Contact> phoneColumn = new TextColumn<Contact>(){
@Override
public String getValue(Contact contact) {
return contact.phone;
}
};
service.getContactInfo(callback);
// Add the columns.
table.addColumn(nameColumn, "Name");
table.addColumn(addressColumn, "Address");
table.setRowCount(CONTACTS.size(), true);
table.setRowData(0, CONTACTS);
RootPanel.get().add(table);
}
公共类CellTableExample实现入口点{
私有静态类联系人
{
私有字符串地址;
私有字符串名称;
私人串电话=”;
公共联系人(字符串名称、字符串地址、字符串电话){
超级();
this.address=地址;
this.name=名称;
this.phone=getPhoneNumber(name);
}
}
公共字符串getPhoneNumber(字符串名称)
{
字符串pNum=“”;
SQLRunnerAsync服务=(SQLRunnerAsync)GWT.create(SQLRunner.class);
AsyncCallback callback=新的AsyncCallback()
{
@凌驾
失败时的公共无效(可丢弃)
{
}
@凌驾
成功时公共无效(ArrayList结果)
{
pNum=lt;
}
};
service.findPhoneNum(名称,回调);
返回pNum;
}
//要显示的数据列表。
专用静态列表联系人=Arrays.asList(
新联系人(“约翰”,“第四大道123号asdf asdf asdf”),
新联系人(“玛丽”,“兰瑟巷222号”)
);
@凌驾
moduleload()上的公共void{
CellTable=新的CellTable();
SQLRunnerAsync服务=(SQLRunnerAsync)GWT.create(SQLRunner.class);
AsyncCallback callback=新的AsyncCallback()
{
@凌驾
失败时的公共无效(可丢弃)
{
}
@凌驾
成功时公共无效(ArrayList结果)
{
compFlexTable.setPageSize(result.size());
Contact[]contactArr=新联系人[result.size()];
对于(int i=0;i您误解了程序的执行顺序。在getPhoneNumber中,您将pNum设置为“”,启动异步请求,然后返回pNum。pNum仍然为“”稍后,当异步请求返回时,pNum设置为result
,但此时为时已晚-您的celltable已呈现
基本上,调用render后,您不能期望任何异步调用及时完成以准确呈现表。您需要的所有数据必须在呈现之前立即可用,否则它将不会显示。您可以在请求CellTable呈现自身之前对数据提供程序进行子类化以执行这些额外的检索。使用正如@Riley所说的异步数据提供者
有关更多参考,请使用以下链接