Witam! Postanowiłem się wkręcić w programowanie javy i na pierwszy strzał padło na smartgwt. Przerobiłem przykład z: http://www.javacodegeeks.com/2011/01/advanced-smartgwt-tutorial-part-1.html
Ale jedna rzecz nie daje mi spokoju.
Jeśli w konstruktorze klasy MainArea.java stworze kod gridu dodającego nowy wpis apliakcja działa dobrze, błąd wyświetlania zaczyna się gdy stworze klasę dajmy na to MyDataGrid.java
package com.javacodegeeks.smartgwt.appui.client.ui;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.types.Autofit;
import com.smartgwt.client.types.ListGridEditEvent;
import com.smartgwt.client.types.RowEndEditAction;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
public class MyDataGrid extends HLayout {
public MyDataGrid() {
ListGridRecord[] data = new ListGridRecord[]{
createRecord("US", "United States", 298444215),
createRecord("CH", "China", 1313973713),
createRecord("JA", "Japan", 127463611)
};
final ListGrid countryGrid = new ListGrid();
countryGrid.setWidth(500);
countryGrid.setAutoFitMaxRecords(6);
countryGrid.setAutoFitData(Autofit.VERTICAL);
countryGrid.setCanEdit(true);
countryGrid.setEditEvent(ListGridEditEvent.CLICK);
countryGrid.setListEndEditAction(RowEndEditAction.NEXT);
ListGridField countryCodeField = new ListGridField("countryCode", "Country Code");
ListGridField nameField = new ListGridField("countryName", "Country");
ListGridField populationField = new ListGridField("population", "Population");
countryGrid.setFields(countryCodeField, nameField, populationField);
countryGrid.setData(data);
IButton button = new IButton("Dodaj nowy");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
countryGrid.startEditingNew();
}
});
VLayout vLayout = new VLayout(20);
vLayout.addMember(countryGrid);
vLayout.addMember(button);
vLayout.draw();
}
public ListGridRecord createRecord(String countryCode, String countryName, int population) {
ListGridRecord record = new ListGridRecord();
record.setAttribute("countryCode", countryCode);
record.setAttribute("countryName", countryName);
record.setAttribute("population", population);
return record;
}
}
Oraz dodam to do MainArea.java
package com.javacodegeeks.smartgwt.appui.client.ui;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
public class MainArea extends VLayout {
private HLayout hLayout;
private VLayout mainLayout;
public MainArea() {
super();
mainLayout = new VLayout();
mainLayout.setWidth100();
mainLayout.setHeight100();
hLayout = new MyDataGrid();
mainLayout.addMember(hLayout);
this.addMember(mainLayout);
}
}
W tedy dostaje dość nie pożądany efekt, który wygląda tak: