日期:2014-05-16  浏览次数:20354 次

ListGrid远程加载json字符串数据
首先保证加入json的jar.
commons-beanutils-1.7.jar
commons-collections-3.2.1.jar
commons-lang-2.4.jar
ezmorph-1.0.6.jar
json-lib-2.2.3-jdk13.jar
morph-1.1.1.jar



WEB-INF/shared/ds/countryDS4.ds.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- recordXPath就是countryData.xml里面每一行的节点名字 -->
<DataSource ID="countryDS4" dataFormat="json">
	<fields>
		<field name="countryCode" title="Code" />
		<field name="countryName" title="Country" />
		<field name="capital" title="Capital" />
	</fields>
	<operationBindings>
		<operationBinding>
			<operationType>fetch</operationType>
			<dataURL>../json_fetch.do</dataURL>
		</operationBinding>
		<operationBinding>
			<operationType>add</operationType>
			<dataURL>../json_add.do</dataURL>
		</operationBinding>
		<operationBinding>
			<operationType>update</operationType>
			<dataURL>../json_update.do</dataURL>
		</operationBinding>
		<operationBinding>
			<operationType>remove</operationType>
			<dataURL>../json_delete.do</dataURL>
		</operationBinding>
	</operationBindings>
</DataSource>



WebRoot/test/datasource4.js
isc.ListGrid.create({
    ID: "countryList",
    width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
    dataSource: countryDS4,
    autoFetchData: true
});




WebRoot/test/datasource4.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/iscTaglib.xml" prefix="isomorphic" %>
<html>
	<HEAD>
		<title>远程返回xml类型做data</title>
		<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<SCRIPT>var isomorphicDir="../isomorphic/";</SCRIPT>
		<SCRIPT SRC=../isomorphic/system/modules/ISC_Core.js></SCRIPT>
		<SCRIPT SRC=../isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
		<SCRIPT SRC=../isomorphic/system/modules/ISC_Containers.js></SCRIPT>
		<SCRIPT SRC=../isomorphic/skins/SmartClient/ISC_DataBinding.js></SCRIPT>
		<SCRIPT SRC=../isomorphic/system/modules/ISC_Grids.js></SCRIPT>
		<SCRIPT SRC=../isomorphic/system/modules/ISC_Forms.js></SCRIPT>
		<SCRIPT SRC=../isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
		<SCRIPT SRC=../isomorphic/skins/SmartClient/load_skin.js></SCRIPT>
		<script type="text/javascript">
			<isomorphic:loadDS ID="countryDS4" /> 
		</script>
	</HEAD>
	<BODY BGCOLOR='papayawhip' MARGINHEIGHT=0 MARGINWIDTH=0 LEFTMARGIN=0 TOPMARGIN=0>
		<script type="text/javascript" src="datasource4.js" charset="UTF-8"></script>
	</BODY>
</HTML>


src/com/controller/SCJSONHelloWord.java

package com.controller;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class SCJSONHelloWord {
	
	@RequestMapping(value="json_fetch.do")
	public ModelAndView fetch(HttpServletRequest request, HttpServletResponse response){
		System.out.println("@@@@@@ fetch");
		try {
			PrintWriter out = response.getWriter();
			List<Map> list = new ArrayList<Map>();
			for(int i=0; i<10; i++