我有一个包含 TabLayoutPanel 的 EntryPoint 类 WebCrawlerOne.java,在其中一个选项卡中我调用了包含 CellTable 的 CrawlerOne.java。我已经尝试了很多,但无法找到任何错误。我尝试搜索相关主题,但在项目运行时,TabLayoutPanel 中仍然看不到 CellTable。
- 我处于标准模式(使用 DOCTYPE html)
- 使用 GWT 2.2.4
已将 CSS 中 TabLayoutPanel 的高度指定为 .gwt-TabLayoutPanel { height: 100%; }
CrawlerOne.ui.xml 看起来像 - 在 g:HTMLpanel 标记中
Hello, <g:Button styleName="{style.important}" ui:field="button" /> <table cellspacing='0' cellpadding='0' style='width:100%;'> <tr> <td valign='top'> <c:CellTable addStyleNames="{style.cellTable}" ui:field="table"/> </td> </tr> </table> <g:TextBox ui:field="box"></g:TextBox> <g:Button ui:field="addSite"></g:Button>
CrawlerOne.java 看起来像——
public class CrawlerOne extends Composite implements HasText {
interface CrawlerOneUiBinder extends UiBinder<Widget, CrawlerOne> {
}
@UiField
CellTable<Contact> table;
@UiField
Button addSite;
@UiField
TextBox box;
public CrawlerOne() {
Widget w = new Widget();
w = onInitialize();
initWidget(w);
}
@UiField
Button button;
@UiHandler("button")
void onClick(ClickEvent e) {
Window.alert("Hello!");
}
public void setText(String text) {
button.setText(text);
}
public String getText() {
return button.getText();
}
/**
* A simple data type that represents a contact with a unique ID.
*/
private static class Contact {
private static int nextId = 0;
private final int id;
private String site;
private String document;
private String pending;
public Contact(String site, String document, String pending) {
nextId++;
this.id = nextId;
this.site = site;
this.document = document;
this.pending = pending;
}
public String getDocument() {
return document;
}
public int getId() {
return id;
}
public String getSite() {
return site;
}
public void setSite(String site) {
this.site = site;
}
public String getPending() {
return pending;
}
}
/**
* The list of data to display.
*/
private static final List<Contact> CONTACTS = new LinkedList<Contact>(Arrays.asList(
new Contact("www.google.com", "12", "123"),
new Contact("www.yahoo.com", "23", "124"),
new Contact("www.rediff.com", "24", "124"),
new Contact("www.gmail.com", "23", "124"),
new Contact("www.facebook.com", "23", "124"),
new Contact("www.flickr.com", "23", "124"),
new Contact("www.youtube.com", "45", "125")));
private static final ProvidesKey<Contact> KEY_PROVIDER =
new ProvidesKey<Contact>() {
@Override
public Object getKey(Contact object) {
return object.getId();
}
};
/**
* Initialize.
*/
public Widget onInitialize() {
table = new CellTable<Contact>(KEY_PROVIDER);
table.setWidth("100%", true);
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
initTableColumns();
// Push the data into the widget.
table.setRowData(CONTACTS);
// Set table width.
table.setWidth("100%");
box = new TextBox();
box.setText("Enter New Site");
addSite = new Button("Add Row");
addSite.addClickHandler(new ClickHandler() {
@UiHandler("addSite")
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
try {
if(box.getValue()=="") {
Window.alert("Error: Invalid Site Value");
box.setText("Enter New Site");
}
else {
CONTACTS.add(new Contact(box.getValue(), "23", "127"));
table.setRowCount(CONTACTS.size(), true);
table.setRowData(CONTACTS);
table.redraw();
}
}catch (Exception e) {
Window.alert("Exception Error: " + e);
}
}
});
// Create the UiBinder.
CrawlerOneUiBinder uiBinder = GWT.create(CrawlerOneUiBinder.class);
Widget widget = uiBinder.createAndBindUi(this);
return widget;
}
private void initTableColumns() {
//code to add columns
}}//end of file
WebCrawlerOne.java 看起来像——
public class WebCrawlerOne implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
TabLayoutPanel menu = new TabLayoutPanel(10, Unit.EM);
menu.add(new CrawlerOne(), "Crawler");
menu.add(new HTML("This is my page!"), "Page 2");
menu.selectTab(0);
RootLayoutPanel.get().add(menu);
}
}
输出看起来像 -
如果直接从 EntryPoint 类运行,则会显示 CellTable。任何帮助表示赞赏。谢谢!