简体   繁体   English

gxt中的分页网格

[英]paging grid in gxt

Im developing the paging grid using GXT 2.1.1, Im retrieving values from database tables using hibernate. 我使用GXT 2.1.1开发分页网格,使用休眠从数据库表中检索值。 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>>() {
                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? 如果我在这里很无知,请忽略我,但是静态类BeanModel的作用是什么?

It implements ModelData but the implementations are empty. 它实现了ModelData,但是实现为空。 If this is the BeanModel your Grid is using then your grid wont have access to the data. 如果这是您的网格正在使用的BeanModel,那么您的网格将无法访问数据。 If that's the case rather have Your BeanModel extend ModelData. 如果是这样,请让您的BeanModel扩展ModelData。

Or is you're vehicle Bean using the BeanModelMarker interface and @BEAN annotation? 还是您是使用BeanModelMarker接口和@BEAN批注的Bean?

I hope I have not misunderstood your situation. 希望我不要误会你的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM