paging grid in gxt
Im developing the paging grid using GXT 2.1.1, Im retrieving values from database tables using hibernate. My code is
public class ExampleSampleTrip extends Composite
{
final GreetingServiceAsync service = GWT.create(GreetingService.class);
static class BeanModel implements ModelData
{
@Override
public <X> X get(String property)
{
// TODO Auto-generated method stub
return null;
}
@Override
public Map<String, Object> getProperties()
{
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<String> getPropertyNames()
{
// TODO Auto-generated method stub
return null;
}
@Override
public <X> X remove(String property)
{
// TODO Auto-generated method stub
return null;
}
@Override
public <X> X set(String property, X value)
{
// TODO Auto-generated method stub
return null;
}
}
List<ColumnConfig> configs = null;
Grid<BeanModel> grid = null;
ContentPanel gridPanel = null;
// loader
PagingLoader<PagingLoadResult<ModelData>> loader = null;
PagingToolBar pagingToolBar = null;
ListStore<BeanModel> store = null;
public ExampleSampleTrip()
{
initComponents();
}
public List<ColumnConfig> getColumns()
{
if ( configs == null)
{
configs = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig();
column.setId("vehicle");
column.setHeader("Vehicle");
column.setWidth(100);
configs.add(column);
column = new ColumnConfig();
column.setId("orgin");
column.setHeader("Orgin");
column.setWidth(100);
configs.add(column);
column = new ColumnConfig();
column.setId("destination");
column.setHeader("Destination");
column.setWidth(100);
configs.add(column);
column = new ColumnConfig();
column.setId("route");
column.setHeader("Route");
column.setWidth(100);
configs.add(column);
column = new ColumnConfig();
column.setId("status");
column.setHeader("Status");
column.setWidth(100);
configs.add(column);
column = new ColumnConfig();
column.setId("currentlocation");
column.setHeader("Current Location");
column.setWidth(100);
configs.add(column);
ColumnModel cm = new ColumnModel(configs);
}
return configs;
}
public Grid<BeanModel> getGrid()
{
if (grid == null)
{
grid = new Grid<BeanModel>(getStore(), new ColumnModel(getColumns()));
grid.addListener(Events.Attach, new Listener<GridEvent<BeanModel>>开发者_Go百科() {
public void handleEvent(GridEvent<BeanModel> be)
{
PagingLoadConfig config = new BasePagingLoadConfig();
config.setLimit(50);
getLoader().load(config);
}
});
grid.setBorders(true);
}
return grid;
}
public ContentPanel getGridPanel()
{
if (gridPanel == null)
{
gridPanel = new ContentPanel();
gridPanel.setFrame(true);
gridPanel.setHeading("Paging Grid");
gridPanel.setLayout(new FitLayout());
gridPanel.add(getGrid());
gridPanel.setSize(600, 350);
gridPanel.setBottomComponent(getPagingToolBar());
}
return gridPanel;
}
public PagingLoader<PagingLoadResult<ModelData>> getLoader()
{
if (loader == null)
{
RpcProxy<List<Vehicle>> proxy=new RpcProxy<List<Vehicle>>(){
@Override
protected void load(Object loadConfig,
AsyncCallback<List<Vehicle>> callback) {
service.getVehicles(callback);
}
};
loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy,new BeanModelReader());
loader.setRemoteSort(true);
loader.load();
}
return loader;
}
public PagingToolBar getPagingToolBar()
{
if (pagingToolBar == null)
{
pagingToolBar = new PagingToolBar(50);
pagingToolBar.bind(getLoader());
}
return pagingToolBar;
}
public ListStore<BeanModel> getStore()
{
if (store == null)
{
store = new ListStore<BeanModel>(getLoader());
}
return store;
}
private void initComponents()
{
initWidget(getGridPanel());
}
}
It is only displaying grid only, its not displaying the values.
my Implementation file is
try {
// This step will read hibernate.cfg.xml and prepare hibernate for
// use
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
System.out.println("Within select");
session = sessionFactory.openSession();
List dataList = session.createQuery(" from Vehicle").list();
dataListArray = new ArrayList<Vehicle>(dataList.size());
for (int i = 0; i < dataList.size(); i++) {
Vehicle datalst = (Vehicle) dataList.get(i);
dataListArray.add(datalst);
}
//cutomerList.add((Customer) dataList);
System.out.println("size---->" + dataListArray.size());
return dataListArray;
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
session.flush();
session.close();
}
Ignore me if I'm being ignorant here but what is the static class BeanModel for?
It implements ModelData but the implementations are empty. If this is the BeanModel your Grid is using then your grid wont have access to the data. If that's the case rather have Your BeanModel extend ModelData.
Or is you're vehicle Bean using the BeanModelMarker interface and @BEAN annotation?
I hope I have not misunderstood your situation.
精彩评论