GWT+GXT 动态列头动态值 Grid

GWT+GXT 动态列头动态值 Grid_第1张图片

 

 

 

 

需求选择串联单栏目,开始时间,结束时间  点击查询。动态查询WebService 得到 动态的列头  和 内容

 

 

页面表现

package com.*****.ccpm.client.page.scoring;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.PagingToolBar;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.*****.ccpm.client.page.scoring.model.WSPagingLoader;
import com.*****.ccpm.client.service.DomServiceAsync;
import com.*****.ccpm.client.service.WSGridServiceAsync;
import com.*****.valuelist.client.ValueListRowBeanReader;
import com.*****.valuelist.client.model.ValueListRowBean;

public class WSScoringNamePanel extends LayoutContainer {
 private  WSPagingLoader loader;
 private  PagingToolBar toolBar ;
 private  ColumnModel cm;
 private  List<ColumnConfig> columns;
 private  Grid<ValueListRowBean> grid ;
 @Override
 protected void onRender(Element parent, int index) {
  super.onRender(parent, index);
  setScrollMode(Scroll.AUTOX);
  
  final WSGridServiceAsync  service = Registry.get("wsService");
  
  FlowLayout  layout = new FlowLayout();
  setLayout(layout);
  
  RpcProxy  proxy = new RpcProxy(){
   @Override
   protected void load(Object loadConfig, AsyncCallback callback) {
    service.getBeanModel((PagingLoadConfig)loadConfig, callback);
   }
  };
  
  loader = new WSPagingLoader(proxy, new ValueListRowBeanReader());
  loader.setRemoteSort(true);
  //loader.load(0,15);                  //每页15条
  
  ListStore<ValueListRowBean> store = new ListStore<ValueListRowBean>(loader);
  toolBar = new PagingToolBar(15); //每页15条
  toolBar.bind(loader);
  
  columns = new ArrayList<ColumnConfig>();
  cm = new ColumnModel(columns);
  
  grid  = new Grid<ValueListRowBean>(store,cm);
  grid.setLoadMask(true);
  grid.setBorders(true);
  
  grid.addListener(Events.RowClick, new Listener<GridEvent>(){
   public void handleEvent(GridEvent be) {
    RowClickRefresh();
   }
  });
  
  ContentPanel panel   = new ContentPanel();
  panel.setFrame(true);
  panel.setButtonAlign(HorizontalAlignment.CENTER);
  panel.setHeaderVisible(false);
  panel.setLayout(new FitLayout());
  panel.setBottomComponent(toolBar);
  panel.setHeight(417);
  panel.setWidth(232);
  panel.add(grid);
  
  add(panel);
  
  Registry.register("WSScoringNamePanel", this);
 }
 
 
 
 @SuppressWarnings("unchecked")
 protected void RowClickRefresh() {
  ValueListRowBean bean = grid.getSelectionModel().getSelectedItem();
  if (bean == null) {
   Info.display("提示", "请选择数据项!");
   return;
  }
  //操作
  String str = bean.get("BillGuid").toString().trim();
  
  if(str == null)
   return ;
  
  
  DomServiceAsync  service =  Registry.get("domService");
  service.getBillItem(str, new AsyncCallback<Map<String,Object>>(){
   public void onFailure(Throwable arg0) {
    Info.display("提示", "连接错误");
   }
   public void onSuccess(Map<String, Object> arg0) {
    if(arg0 == null){
     return ;
    }
    
    SeriesSizePanel panel =(SeriesSizePanel) Registry.get("SizePanel"); // 串联单条目 Panel
    if(panel == null ){
     return;
    }
    ListStore<ValueListRowBean> store = panel.getStore();
    store.removeAll();
    ColumnModel cMode = (ColumnModel) panel.getColumnModel();
    List<ColumnConfig> columns = (List<ColumnConfig>) panel.getColumns();
    columns.clear();
    
    //得到返回的  列表头集合
    List<com.lingran.ccpm.client.model.ColumnModel>  columnList =  (List<com.lingran.ccpm.client.model.ColumnModel>) arg0.get("columnList");
    
    if(columnList == null || columnList.size() ==0){
     Info.display("提示", "查询错误");
     return ;
    }
    //setColumnHeader  修改表头显示
    com.lingran.ccpm.client.model.ColumnModel  model = null;
    ColumnConfig config = null;
    int index = 0;
    for(int i=0;i<columnList.size();i++){
     model = null ;
     config = null;
     
     model = columnList.get(i);
     if(!"0".equals(model.getShow())){
      config = new ColumnConfig(model.getSort(),model.getDeisplay(),Integer.parseInt(model.getShow()));
      columns.add(config);
      cMode.setColumnHeader(index, model.getDeisplay());
      ++index;
     }
    }
    
    
    //set value   添加 返回的  值
    List<ValueListRowBean> beanList = (List<ValueListRowBean>) arg0.get("dataList");
    if(beanList == null || beanList.size()== 0)
     return ;
    for(int i=0;i<beanList.size();i++){
     store.add(beanList.get(i));
//     Window.alert(beanList.get(i).get("NewsGuid").toString());
    }
    store.commitChanges();
   }
  });
 }
 
 
 public ColumnModel getCm() {
  return cm;
 }
 public void setCm(ColumnModel cm) {
  this.cm = cm;
 }
 public List<ColumnConfig> getColumns() {
  return columns;
 }
 public void setColumns(List<ColumnConfig> columns) {
  this.columns = columns;
 }
 public WSPagingLoader getLoader() {
  return loader;
 }
 public void setLoader(WSPagingLoader loader) {
  this.loader = loader;
 }
 public PagingToolBar getToolBar() {
  return toolBar;
 }
 public void setToolBar(PagingToolBar toolBar) {
  this.toolBar = toolBar;
 }

 public Grid<ValueListRowBean> getGrid() {
  return grid;
 }

 public void setGrid(Grid<ValueListRowBean> grid) {
  this.grid = grid;
 }
 
 
 
}

 

servlet

 

package com.*****.ccpm.gwt.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.*****.ccpm.client.page.scoring.model.WSConfig;
import com.*****.ccpm.client.page.scoring.model.WSPagingLoadConfig;
import com.*****.ccpm.client.service.WSGridService;
import com.*****.ccpm.util.WebServiceInvoke;
import com.*****.ccpm.util.XmlDom4jScoringCommon;
import com.*****.valuelist.client.model.ValueListRowBean;

public class GwtWsGrid extends RemoteServiceServlet implements WSGridService{

 private static final long serialVersionUID = -7954852375614764033L;

 public PagingLoadResult<ValueListRowBean> getBeanModel(PagingLoadConfig config) {
  
  HttpServletRequest request = getThreadLocalRequest();
  HttpSession session = request.getSession();
  
  /*
   * 对象转换    WSPagingLoadConfig 重写了  BasePagingLoadConfig  使 WSPagingLoadConfig  可带参数
   */
  WSPagingLoadConfig  wlc = (WSPagingLoadConfig) config;
  Map<String, String> map =  wlc.getParams();
  
  
  //返回的数据结果集
  ArrayList<ValueListRowBean> modelList = new ArrayList<ValueListRowBean>();
  //附和条件的总条数
  int size = 0;
  
  if(map != null){
   String item = map.get(WSConfig.Item);             //栏目
   String beginTime =  map.get(WSConfig.BeginTime);  //查询开始时间
   String endTime = map.get(WSConfig.EndTime);       //查询结束时间
   
   //set offSet
   int offSet = 0;  //起始序列
   
   String sessionItem =  (String) session.getAttribute("WebServiceGrid_Item");// 得到session里的  查询栏目
   if(sessionItem != null ){
    
    //比较栏目  确定  起始序列
    if(sessionItem.equals(item)){
     offSet = config.getOffset();
    }else{
     offSet =0;
     config.setOffset(0);
    }
    
   }else{
    //等于null  是第一次访问
    offSet = config.getOffset();
   }
   
   // set  session    WebServiceGrid_Item
   session.setAttribute("WebServiceGrid_Item", item);
   
   int beginIndex = offSet  +1;
   int endIndex   = beginIndex + 14;
   
   if(item != null){
    if(!"".equals(item)){
     String requestGuid = java.util.UUID.randomUUID().toString();
     String inStr = "<CmdID>" + requestGuid +"</CmdID>" +
     "<CmdType>Score</CmdType><CmdSubType>GetBill</CmdSubType>"+
     "<Info><Head></Head>" +
     "<Field><BeginTime>"+beginTime+"</BeginTime>"
     +"<EndTime>"+endTime+"</EndTime>"
     +"<ColumnName>"+item+"</ColumnName>"
     +"<BeginIndex>"+beginIndex+"</BeginIndex>"+
     "<EndIndex>"+endIndex+"</EndIndex></Field></Info><Note></Note>";
     String outStr = WebServiceInvoke.invoke(inStr); // 访问 WebService
     
     Map<String, Object> xmlMap = XmlDom4jScoringCommon.getSeriesList(outStr);
     List<ValueListRowBean> list = (List<ValueListRowBean>) xmlMap.get("dataList");
     for(int i=0;i<list.size();i++){
      ValueListRowBean  bean = list.get(i);
      modelList.add(bean);
     }
     
     String total = (String) xmlMap.get("total");
     if(total != null ){
      size = Integer.parseInt(total);
     }
    }
   }
  }
  
  return new BasePagingLoadResult<ValueListRowBean>(modelList, config.getOffset(), size);
 }

}

 

你可能感兴趣的:(bean,object,String,webservice,null,gwt)