我有一個EntryPoint類WebCrawlerOne.java,其中包含TabLayoutPanel,並在其中一個選項卡中調用CrawlerOne.java,其中包含CellTable。我嘗試了很多,但無法找到任何錯誤。我試圖搜索相關主題,但仍然在項目運行時,CellTable在TabLayoutPanel中不可見。CellTable在TabLayoutPanel中不可見
- 我在標準模式下使用GWT 2.2.4
- (使用DOCTYPE HTML)所指定的TabLayoutPanel在CSS作爲.gwt-TabLayoutPanel高度{ 高度:100%; }
CrawlerOne.ui.xml看起來like-- 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看起來like--
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看起來like--
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);
}
}
輸出看起來like--
如果直接從入口點類中運行正在顯示的CellTable。任何幫助讚賞。謝謝!
非常感謝! @UiField(provided = true)缺失。由於其他錯誤,我早先刪除了它,然後忘了放回去。非常感謝! :) – Prince 2012-02-17 01:58:18