一个easyui的案例(SSH)

简介: /*  * name :tuzuoquan mail :tuzq@css.com.cn date :2014/02/14 version :0.1  * description:气象信息共享门户系统通用JS,TreeTable CopyRight (C) 2014-02  */ // 获取选中一行的情况,下面的一个参数可以代表一个DataGrid function getSele

/*
 * name :tuzuoquan mail :tuzq@css.com.cn date :2014/02/14 version :0.1
 * description:气象信息共享门户系统通用JS,TreeTable CopyRight (C) 2014-02
 */
// 获取选中一行的情况,下面的一个参数可以代表一个DataGrid
function getSelected(dialogEle) {
 // 获取选中一行的情况。
 var datagrid = $("#fileInfoDataGrid").datagrid('getSelected');
// alert(datagrid.fileName + " " + datagrid.filePath + " "
//   + datagrid.lastModified + " " + datagrid.fileType);
 if(datagrid == null){
  alert("对不起!您还没有选择文件!");
 } else {
  if(datagrid.fileType == "文件夹"){
   alert("对不起,您选择的是文件夹,请您选择确切的文件!");
  } else {
   //alert($(".service1 #path").length);
   //给这个文本域赋值
   $(".service1 #path").attr("value",datagrid.filePath);
   dialogEle.dialog("close");
  }
 }
}

// 获取选中多行的情况
function getSelections() {
 var ids = [];
 var rows = $("#fileInfoDataGrid").datagrid('getSelections');
 for (var i = 0; i < rows.length; i++) {
  ids.push(rows[i].filePath);
 }

 alert(ids.join(':'));
}

//选中指定行
function selectRow(rowNum){
 $("#fileInfoDataGrid").datagrid('selectRow',rowNum);
}

//不选中指定行
function unselectRow(rowNum){
 $("#fileInfoDataGrid").datagrid('unselectRow',rowNum);
}

function clearSelections(){
 $("#fileInfoDataGrid").datagrid('clearSelections');
}

$(function() {
 $("#dialog-diskFileInfo").dialog({
  resizable : false,
  height : 500,
  minHeight : 150,
  width : 1015,
  modal : true,
  show : "blind",
  hide : "explode",
  closeOnEscape : true,
  autoOpen : false,
  draggable : true,
  buttons : {
   "确定" : function() {
    $.fn.diskFileDialogEleBtnCheckOk($(this),
      $("#diskFileStructureTree"), $("#fileInfoDataGrid"));
   },
   "取消" : function() {
    $(this).dialog("close");
   }
  }
 });

 // 带有class属性为openDiskFileInfoDialog的元素,为这个元素添加点击事件
 $("#openDiskFileInfoDialog").bind("click", function() {
  // 加载数据
  $("#diskFileStructureTree").tree({
   height : 355,
   checkbox : false,
   url : basePath + "/onlinegraph/treeDataAction_treeNodes.action",
   method : 'post',
   animate : true,
   dnd : true,
   lines : true,
   onClick : function(node) {
//    $("#fileInfoDataGrid").datagrid({
//     // 通过这个获得参数
//     url : basePath
//       + "/onlinegraph/fileInfoAction_folderFileInfoList.action?path=" + node.id,
//     method : 'post'
//    });
    
    $("#fileInfoDataGrid").datagrid('load', {
       page : 1,
       pageSize : "10",
       path:node.id
      });
    
    //$("#fileInfoDataGrid").datagrid('reload');
   },
   onBeforeExpand : function(node, param) {
    $("#diskFileStructureTree").tree('options').url = basePath
      + "/onlinegraph/treeDataAction_treeNodeList.action?path="
      + node.id;
   }
  });

  // 打开表格
  $("#fileInfoDataGrid").datagrid({
   height:325,
   width:815,
   // 通过这个获得参数
   url : basePath
     + "/onlinegraph/fileInfoAction_folderFileInfoList.action",
   // 行阴影,但目前看没有效果
   striped : true,
   method : 'post',
   nowrap : false,
   border : false,
   singleSelect : true,
   // 自适应窗口大小变化
   fit : true,
   title : '文件信息',
   fitColumns : true,
   rownumbers : true,
   idField : 'filePath',
   collapsible : true,
   sortName:'fileName',
   // 排序规则
   sortOrder : 'desc',
   // 本地排序,不是在服务器端排
   remoteSort : false,
   frozenColumns : [[{
      field : 'checkbox',
      checkbox : true
     }]],
   columns : [[{
      field : 'fileName',
      title : '名称',
      sortable : true,
      sortable : true,
      width : 50
     }, {
      field : 'filePath',
      title : '文件路径',
      sortable : true,
      sortable : true,
      width : 160
     }, {
      field : 'lastModified',
      title : '修改日期',
      sortable : true,
      sortable : true,
      width : 100
     }, {
      field : 'fileType',
      title : '类型',
      sortable : true,
      width : 50,
      align : 'left'
     }, {
      field : 'fileSize',
      title : '大小',
      sortable : true,
      width : 50,
      align : 'left'
     }]],
   // 事件调用的方式
   onLoadSuccess : function() {
   },
   onDblClickRow:function(index,row){
    //alert("index == " + index + " row == " + row.filePath);
    
    if(row.fileType == "文件夹"){
     alert("对不起,您选择的是文件夹,请您选择确切的文件!");
    } else {
     //alert($(".service1 #path").length);
     //给这个文本域赋值
     $(".service1 #path").attr("value",row.filePath);
     $("#dialog-diskFileInfo").dialog("close");
    }
   },
   pagination : true
  });

  var p = $("#fileInfoDataGrid").datagrid('getPager');
  $(p).pagination({
   pageList:[5,10,20,30,40,50,100],
   //layout:['list','sep','first','prev','links','next','last','sep','refresh'],
   beforePageText : '第',
   afterPageText : '页  共{pages}页',
   displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
   showPageList:true,
   showRefresh:true,
   onSelectPage : function(pageNumber, pageSize) {
    $(this).pagination('loading');
    $(this).pagination('loaded');
    
    // 选择相应的页码时刷新显示内容列表
    $("#fileInfoDataGrid").datagrid('load', {
       page : pageNumber,
       pageSize : pageSize
      });

    $("#fileInfoDataGrid").datagrid('reload');

    // $("#fileInfoDataGrid").datagrid({
    // //通过这个获得参数
    // url: basePath +
    // "/onlinegraph/fileInfoAction_folderFileInfoList.action?page="
    // + pageNumber + "&pageSize=" + pageSize,
    // method:'post'
    // });
   },
   onBeforeRefresh : function(pageNumber, pageSize) {
    // 刷新触发事件
    $(this).pagination('loading');
    $(this).pagination('loaded');
   },
   onRefresh : function(pageNumber, pageSize) {
    //alert("pageNumber = " + pageNumber + " pageSize = " + pageSize);
    // 上一页触发事件
    $("#fileInfoDataGrid").datagrid('load', {
       page : pageNumber,
       pageSize : pageSize
      });

    $(this).pagination('loading');
    $(this).pagination('loaded');

    $("#fileInfoDataGrid").datagrid('reload');
   },
   onChangePageSize : function(pageSize) {
    $(this).pagination('loading');
                $(this).pagination('loaded');
   }
  });

  $("#dialog-diskFileInfo").dialog("open");
 });

 // 插件的第一个参数表示的是弹出的dialog元素
 $.fn.diskFileDialogEleBtnCheckOk = function(dialogEle,
   diskFileStructureTree, fileInfoDataGrid) {

  // 获得选中列
  getSelected(dialogEle);
    
  //获取选中多行的信息
  //getSelections();
  
  //选中第二行
  //selectRow(2);
    
  //不选中第三行
  //unselectRow(2);
  
  //清除所有的选中行
  //clearSelections();
 }
});

 

struts2配置:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
 <package name="system_onlinegraph" namespace="/onlinegraph" extends="global-struts-default">
  <action name="treeDataAction_*" class="cn.com.css.misps.onlinegraph.web.action.TreeDataAction" method="{1}">
   <result name="treeNodes" type="json">
    <param name="root">treeList</param>
   </result>
   <result name="treeNodeList" type="json">
    <param name="root">treeNodeList</param>
   </result>
  </action>
  
  <action name="fileInfoAction_*" class="cn.com.css.misps.onlinegraph.web.action.FileInfoAction" method="{1}">
   <result type="json"></result>
  </action>
    </package>
</struts>

 

 

 

action的写法:

package cn.com.css.misps.onlinegraph.web.action;

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

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.com.css.common.action.BaseAction;
import cn.com.css.misps.onlinegraph.bean.TreeDataBean;
import cn.com.css.misps.onlinegraph.service.ITreeDataService;
import cn.com.css.misps.onlinegraph.service.impl.TreeDataServiceImpl;
import cn.com.css.misps.onlinegraph.util.ProductsStorageUtils;

/**
 * @brief FileInfoAction.java 通过这个类查看文件夹下的文件信息
 * @attention
 * @author 涂作权
 * @date 2014-2-25
 * @note begin modify by null
 */
@SuppressWarnings("serial")
@Scope("prototype")
@Controller
public class FileInfoAction extends BaseAction {
 private int total = 0;
 private List<Object> rows;
 private String path;
 private String page;
 private String pageSize;
 
 /**
  * \brief 通过此方法返回指定文件夹下的文件信息
  *
  * @return
  * @attention
  * @author 涂作权
  * @date 2014-2-25
  * @note begin modify by null
  */
 public String folderFileInfoList() {
  rows = new ArrayList<Object>();
  ITreeDataService treeDataService = new TreeDataServiceImpl();

  // 如果path为空,显示的是根目录的文件信息
  List<TreeDataBean> list = null;
  
  //先获得当前页和每页大小,如果在
  int intPage = Integer.parseInt((page == null || page == "0") ? "1":page);
  System.out.println("intPage  ==  "+intPage);
  
  if (path == null) {
   // 如果path为空,显示的是根目录的文件信息
   list = treeDataService.getAllFileList(ProductsStorageUtils.micapsAbsolutePath);
  } else {
   // 如果文件路径是空,查询指定目录下的文件信息
   list = treeDataService.getAllFileList(path);
  }
  
  //每页显示条数
  int number = Integer.parseInt((pageSize == null || pageSize == "0") ? "10":pageSize);
  
  if ((pageSize == null || pageSize == "0")) {
   pageSize = "10";
   page = "1";
  }
  
  //每页的开始记录  第一页为1, 第二页为number+1
  int start = (intPage - 1) * number;
  int end = ((start + number) < list.size()) ? start + number : list.size();
  
  //注意要将每个对象的内容放到map集合中,然后将每个map放到rows集合中
  for (int i = start; i < end; i++) {
   Map<String, Object> map = new HashMap<String, Object>();
   map.put("fileName", list.get(i).getFileName());
   map.put("filePath", list.get(i).getFilePath());
   map.put("lastModified", list.get(i).getLastModified());
   map.put("fileType", list.get(i).getFileType());
   map.put("fileSize", list.get(i).getFileSize());
   rows.add(map);
  }
  
  total = list.size();
  
  return SUCCESS;
 }

 /**
  * @return the total
  */
 public int getTotal() {
  return total;
 }

 /**
  * @param total the total to set
  */
 
 public void setTotal(int total) {
  this.total = total;
 }

 /**
  * @return the rows
  */
 public List<Object> getRows() {
  return rows;
 }

 /**
  * @param rows the rows to set
  */
 
 public void setRows(List<Object> rows) {
  this.rows = rows;
 }

 /**
  * @return the path
  */
 public String getPath() {
  return path;
 }

 /**
  * @param path the path to set
  */
 
 public void setPath(String path) {
  this.path = path;
 }

 /**
  * @return the page
  */
 public String getPage() {
  return page;
 }

 /**
  * @param page the page to set
  */
 
 public void setPage(String page) {
  this.page = page;
 }

 /**
  * @return the pageSize
  */
 public String getPageSize() {
  return pageSize;
 }

 /**
  * @param pageSize the pageSize to set
  */
 
 public void setPageSize(String pageSize) {
  this.pageSize = pageSize;
 }
}

目录
相关文章
|
30天前
|
JavaScript 前端开发 Java
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Jsp页面
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Jsp页面
9 0
|
30天前
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——OpSessionview实现
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——OpSessionview实现
12 0
|
30天前
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——EmpDao层代码
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——EmpDao层代码
16 0
|
30天前
|
Java
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Action的实现类
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Action的实现类
10 0
|
30天前
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——工具类
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——工具类
10 0
|
30天前
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——DeptDao层代码
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——DeptDao层代码
9 0
|
30天前
|
XML Java 数据库连接
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——hibernate的config文件(hibernate.cfg.xml)
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——hibernate的config文件(hibernate.cfg.xml)
10 0
|
30天前
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Dept实体类和对应的配置信息
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Dept实体类和对应的配置信息
13 1
|
30天前
|
JavaScript Java 数据库连接
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Emp实体类和对应的配置信息
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Emp实体类和对应的配置信息
23 0
|
11月前
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——struts.xml配置详情
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——struts.xml配置详情
49 0