在gxt中寻呼网格

时间:2010-09-03 07:00:31

标签: java hibernate gxt

我正在使用GXT 2.1.1开发分页网格,我正在使用hibernate从数据库表中检索值。我的代码是

 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>>() {
                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());
    }

}

它仅显示网格,不显示值。

我的实施文件是

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();
}

1 个答案:

答案 0 :(得分:1)

如果我在这里无知,请忽略我但是静态类BeanModel是什么?

它实现了ModelData,但实现是空的。 如果这是您的网格使用的BeanModel,那么您的网格将无法访问数据。 如果是这种情况,那么你的BeanModel会扩展ModelData。

或者你是使用BeanModelMarker接口和@BEAN注释的车辆Bean?

我希望我没有误解你的情况。