...
作者: yongtree 链接:http://www.javaeye.com/topic/274081 发表时间: 2008年11月22日
声明:本文系JavaEye网站发布的原创文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!
使用json-lib-1.5.jar来处理java和json的转换的确给我们带来了不少的方便,但是在处理存在级联关系的pojo时,使用fromObject时就会报:net.sf.json.JSONException: There is a cycle in the hierarchy!,使得生成json掉入了级联的循环陷阱中,但是pojo肯定会存在级联关系,怎么解决这个问题呢?
当然你可以拼写字符串,也可以使用map,但是仍然不是非常方便,需要一个个的处理属性。其实json.jar给我们提供了一个相关的处理来应对这样的情况,就是通过JSON的配置类JsonConfig。如下代码所示:
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
String[] excludes = { "poNewsArticle", "class" };
jsonConfig.setExcludes(excludes);
PoNewsComment c=newsService.getCommentById(id);
JSONObject jsonObject = JSONObject.fromObject(c);
System.out.println(jsonObject.toString());
PoNewsComment.java
public class PoNewsComment implements java.io.Serializable {
// Fields
private Integer commentId;
private PoNewsArticle poNewsArticle;//关联的新闻的pojo
private String comment;
private String commenter;
private Date commentTime;
private short commentStatus;
private String commenterIp;
//省略set、get方法
}
其实其他的情况都可以使用JsonConfig来处理,包括时间转换,数据类型的转换等等。下一篇将介绍一个操作json的通用工具类。
已有 0 人发表回复,猛击->>这里<<-参与讨论
JavaEye推荐
- 你想过自己的博客制作成书吗 - JavaEye推出博客自动生成电子书功能!
- 搜狐网站诚聘Java、PHP和C++工程师
- 加入阿里巴巴,发展潜力无限
- Windows7在微软WinHEC 2008上揭开神秘面纱
"Content-Type" content="text/html; charset=utf-8"...
作者: liliugen 链接:http://www.javaeye.com/topic/274069 发表时间: 2008年11月22日
声明:本文系JavaEye网站发布的原创文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!
树形结构代码:
"Content-Type" content="text/html; charset=utf-8" />
EXT2.2 Test
By Roger
浮动窗口js代码:
/*
* Ext JS Library 2.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.onReady(function(){
var win;
var button = Ext.get('show-btn');
button.on('click', function(){
// create the window on the first click and reuse on subsequent clicks
if(!win){
win = new Ext.Window({
applyTo : 'hello-win',
layout : 'fit',
width : 500,
height : 300,
closeAction :'hide',
plain : true,
items : new Ext.TabPanel({
applyTo : 'hello-tabs',
autoTabs : true,
activeTab : 0,
deferredRender : false,
border : false
}),
buttons: [{
text : 'Submit',
disabled : true
},{
text : 'Close',
handler : function(){
win.hide();
}
}]
});
}
win.show(button);
});
});
googlemap代码:
/*
* Ext JS Library 2.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.onReady(function(){
var mapwin;
var button = Ext.get('show-btn');
button.on('click', function(){
// create the window on the first click and reuse on subsequent clicks
if(!mapwin){
mapwin = new Ext.Window({
layout: 'fit',
title: 'GMap Window',
closeAction: 'hide',
width:400,
height:400,
x: 40,
y: 60,
items: {
xtype: 'gmappanel',
region: 'center',
zoomLevel: 14,
gmapType: 'map',
mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'],
mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],
setCenter: {
geoCodeAddr: '4 Yawkey Way, Boston, MA, 02215-3409, USA',
marker: {title: 'Fenway Park'}
},
markers: [{
lat: 42.339641,
lng: -71.094224,
marker: {title: 'Boston Museum of Fine Arts'},
listeners: {
click: function(e){
Ext.Msg.alert('Its fine', 'and its art.');
}
}
},{
lat: 42.339419,
lng: -71.09077,
marker: {title: 'Northeastern University'}
}]
}
});
}
mapwin.show();
});
});
/*
* Ext JS Library 2.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @author Shea Frederick
*/
Ext.namespace('Ext.ux');
/**
*
* @class GMapPanel
* @extends Ext.Panel
*/
Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
initComponent : function(){
var defConfig = {
plain: true,
zoomLevel: 3,
yaw: 180,
pitch: 0,
zoom: 0,
gmapType: 'map',
border: false
};
Ext.applyIf(this,defConfig);
Ext.ux.GMapPanel.superclass.initComponent.call(this);
},
afterRender : function(){
var wh = this.ownerCt.getSize();
Ext.applyIf(this, wh);
Ext.ux.GMapPanel.superclass.afterRender.call(this);
if (this.gmapType === 'map'){
this.gmap = new GMap2(this.body.dom);
}
if (this.gmapType === 'panorama'){
this.gmap = new GStreetviewPanorama(this.body.dom);
}
if (typeof this.addControl == 'object' && this.gmapType === 'map') {
this.gmap.addControl(this.addControl);
}
if (typeof this.setCenter === 'object') {
if (typeof this.setCenter.geoCodeAddr === 'string'){
this.geoCodeLookup(this.setCenter.geoCodeAddr);
}else{
if (this.gmapType === 'map'){
var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
this.gmap.setCenter(point, this.zoomLevel);
}
if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
}
}
if (this.gmapType === 'panorama'){
this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
}
}
GEvent.bind(this.gmap, 'load', this, function(){
this.onMapReady();
});
},
onMapReady : function(){
this.addMarkers(this.markers);
this.addMapControls();
this.addOptions();
},
onResize : function(w, h){
if (typeof this.getMap() == 'object') {
this.gmap.checkResize();
}
Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
},
setSize : function(width, height, animate){
if (typeof this.getMap() == 'object') {
this.gmap.checkResize();
}
Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
},
getMap : function(){
return this.gmap;
},
getCenter : function(){
return this.getMap().getCenter();
},
getCenterLatLng : function(){
var ll = this.getCenter();
return {lat: ll.lat(), lng: ll.lng()};
},
addMarkers : function(markers) {
if (Ext.isArray(markers)){
for (var i = 0; i < markers.length; i++) {
var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
}
}
},
addMarker : function(point, marker, clear, center, listeners){
Ext.applyIf(marker,G_DEFAULT_ICON);
if (clear === true){
this.getMap().clearOverlays();
}
if (center === true) {
this.getMap().setCenter(point, this.zoomLevel);
}
var mark = new GMarker(point,marker);
if (typeof listeners === 'object'){
for (evt in listeners) {
GEvent.bind(mark, evt, this, listeners[evt]);
}
}
this.getMap().addOverlay(mark);
},
addMapControls : function(){
if (this.gmapType === 'map') {
if (Ext.isArray(this.mapControls)) {
for(i=0;i
}
}else if(typeof this.mapControls === 'string'){
this.addMapControl(this.mapControls);
}else if(typeof this.mapControls === 'object'){
this.getMap().addControl(this.mapControls);
}
}
},
addMapControl : function(mc){
var mcf = window[mc];
if (typeof mcf === 'function') {
this.getMap().addControl(new mcf());
}
},
addOptions : function(){
if (Ext.isArray(this.mapConfOpts)) {
var mc;
for(i=0;i
}
}else if(typeof this.mapConfOpts === 'string'){
this.addOption(this.mapConfOpts);
}
},
addOption : function(mc){
var mcf = this.getMap()[mc];
if (typeof mcf === 'function') {
this.getMap()[mc]();
}
},
geoCodeLookup : function(addr) {
this.geocoder = new GClientGeocoder();
this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
},
addAddressToMap : function(response) {
if (!response || response.Status.code != 200) {
Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
}else{
place = response.Placemark[0];
addressinfo = place.AddressDetails;
accuracy = addressinfo.Accuracy;
if (accuracy === 0) {
Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
}else{
if (accuracy < 7) {
Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.
Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
}else{
point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
}
}
}
}
}
});
Ext.reg('gmappanel',Ext.ux.GMapPanel);
拖拽效果代码:
/*
* Ext JS Library 2.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/*
* Ext JS Library 2.1
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.onReady(function(){
var myData = {
records : [
{ name : "Rec 0", column1 : "0", column2 : "0" },
{ name : "Rec 1", column1 : "1", column2 : "1" },
{ name : "Rec 2", column1 : "2", column2 : "2" },
{ name : "Rec 3", column1 : "3", column2 : "3" },
{ name : "Rec 4", column1 : "4", column2 : "4" },
{ name : "Rec 5", column1 : "5", column2 : "5" },
{ name : "Rec 6", column1 : "6", column2 : "6" },
{ name : "Rec 7", column1 : "7", column2 : "7" },
{ name : "Rec 8", column1 : "8", column2 : "8" },
{ name : "Rec 9", column1 : "9", column2 : "9" }
]
};
// Generic fields array to use in both store defs.
var fields = [
{name: 'name', mapping : 'name'},
{name: 'column1', mapping : 'column1'},
{name: 'column2', mapping : 'column2'}
];
// create the data store
var firstGridStore = new Ext.data.JsonStore({
fields : fields,
data : myData,
root : 'records'
});
// Column Model shortcut array
var cols = [
{ id : 'name', header: "Record Name", width: 160, sortable: true, dataIndex: 'name'},
{header: "column1", width: 50, sortable: true, dataIndex: 'column1'},
{header: "column2", width: 50, sortable: true, dataIndex: 'column2'}
];
// declare the source Grid
var firstGrid = new Ext.grid.GridPanel({
ddGroup : 'secondGridDDGroup',
store : firstGridStore,
columns : cols,
enableDragDrop : true,
stripeRows : true,
autoExpandColumn : 'name',
width : 325,
region : 'west',
title : 'First Grid'
});
var secondGridStore = new Ext.data.JsonStore({
fields : fields,
root : 'records'
});
// create the destination Grid
var secondGrid = new Ext.grid.GridPanel({
ddGroup : 'firstGridDDGroup',
store : secondGridStore,
columns : cols,
enableDragDrop : true,
stripeRows : true,
autoExpandColumn : 'name',
width : 325,
region : 'center',
title : 'Second Grid'
});
//Simple 'border layout' panel to house both grids
var displayPanel = new Ext.Panel({
width : 650,
height : 300,
layout : 'border',
renderTo : 'panel',
items : [
firstGrid,
secondGrid
],
bbar : [
'->', // Fill
{
text : 'Reset both grids',
handler : function() {
//refresh source grid
firstGridStore.loadData(myData);
//purge destination grid
secondGridStore.removeAll();
}
}
]
});
// used to add records to the destination stores
var blankRecord = Ext.data.Record.create(fields);
/****
* Setup Drop Targets
***/
// This will make sure we only drop to the view container
var firstGridDropTargetEl = firstGrid.getView().el.dom.childNodes[0].childNodes[1];
var firstGridDropTarget = new Ext.dd.DropTarget(firstGridDropTargetEl, {
ddGroup : 'firstGridDDGroup',
copy : true,
notifyDrop : function(ddSource, e, data){
// Generic function to add records.
function addRow(record, index, allItems) {
// Search for duplicates
var foundItem = firstGridStore.find('name', record.data.name);
// if not found
if (foundItem == -1) {
firstGridStore.add(record);
// Call a sort dynamically
firstGridStore.sort('name', 'ASC');
//Remove Record from the source
ddSource.grid.store.remove(record);
}
}
// Loop through the selections
Ext.each(ddSource.dragData.selections ,addRow);
return(true);
}
});
// This will make sure we only drop to the view container
var secondGridDropTargetEl = secondGrid.getView().el.dom.childNodes[0].childNodes[1]
var destGridDropTarget = new Ext.dd.DropTarget(secondGridDropTargetEl, {
ddGroup : 'secondGridDDGroup',
copy : false,
notifyDrop : function(ddSource, e, data){
// Generic function to add records.
function addRow(record, index, allItems) {
// Search for duplicates
var foundItem = secondGridStore.find('name', record.data.name);
// if not found
if (foundItem == -1) {
secondGridStore.add(record);
// Call a sort dynamically
secondGridStore.sort('name', 'ASC');
//Remove Record from the source
ddSource.grid.store.remove(record);
}
}
// Loop through the selections
Ext.each(ddSource.dragData.selections ,addRow);
return(true);
}
});
});
已有 0 人发表回复,猛击->>这里<<-参与讨论
JavaEye推荐
- 搜狐网站诚聘Java、PHP和C++工程师
- 你想过自己的博客制作成书吗 - JavaEye推出博客自动生成电子书功能!
- 加入阿里巴巴,发展潜力无限
- Windows7在微软WinHEC 2008上揭开神秘面纱
也许很多人会认为Flex跟Flash一样主要是用来制作动画...
作者: ilinker 链接:http://www.javaeye.com/topic/274015 发表时间: 2008年11月22日
声明:本文系JavaEye网站发布的原创文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!
|
1 Flex与Flash ![]()
http://examples.adobe.com/flex3/consulting/styleexplorer/Flex3StyleExplorer.html#
Flex各种控件组建官方实例代码,不用买任何书,只要看完这个例子,基本就能够进行Flex开发了:http://examples.adobe.com/flex3/componentexplorer/explorer.html 10 可以用任何你熟悉的WEB编程平台作为后台数据访问层,可以使用 asp.net,php,jsp,webservice 。 12 Flex的最新版本是 3.0.1 下载地址为: http://www.adobe.com/cfusion/entitlement/index.cfm?e=flex3email
|
已有 0 人发表回复,猛击->>这里<<-参与讨论
JavaEye推荐
- 加入阿里巴巴,发展潜力无限
- 搜狐网站诚聘Java、PHP和C++工程师
- 你想过自己的博客制作成书吗 - JavaEye推出博客自动生成电子书功能!
- Windows7在微软WinHEC 2008上揭开神秘面纱
参考网站: ...
作者: hubenxuan 链接:http://www.javaeye.com/topic/272620 发表时间: 2008年11月21日
声明:本文系JavaEye网站发布的原创文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!
高手请指教啊..我想做个类似 天津日报 这样效果的网站 可是不知道图片是怎么自动划分 热点连接的.
参考网站: http://epaper.tianjindaily.com.cn/tjrb/tjrb/2008-11/21/node_4482.htm
已有 0 人发表回复,猛击->>这里<<-参与讨论
JavaEye推荐
- 你想过自己的博客制作成书吗 - JavaEye推出博客自动生成电子书功能!
- Windows7在微软WinHEC 2008上揭开神秘面纱
- 搜狐网站诚聘Java、PHP和C++工程师
- 加入阿里巴巴,发展潜力无限
请看下面介绍:
作者: CharlesCui 链接:http://www.javaeye.com/topic/272354 发表时间: 2008年11月21日
声明:本文系JavaEye网站发布的原创文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!
Demo如下,大家拍砖吧!
请看下面介绍:
程序代码:
下面代码负责实现和旺旺IM通讯的接口,这里只响应了onClick事件。
using System.Linq;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using wwsdkcomLib;
using System.Xml;
namespace JSHelper
{
public class Global
{
public static int lPluginCookie;
public static int lCookie;
public static object pSlot;
public static string appid = "18265";
}
[ComVisible(true),
Guid("B221A17A-D3E7-44df-AD67-D45CFA4B5229"),
ClassInterface(ClassInterfaceType.None)]
public class Class1 : ISDKPlugin2
{
public void OnConnect(object pApplication, int lPluginCookie)
{
// OnConnect 不建议使用末态对话框
//ISDKPluginQueryResult pqr = (pApplication as ISDKApplication3).GetSubScriptionInfo(lPluginCookie) as ISDKPluginQueryResult;
//Global.appid = pqr.appID;
}
public void OnDisconnect(object pApplication, int lPluginCookie)
{
// OnDisConnect 不建议使用末态对话框
// MessageBox.Show("我被卸载了", "csharp helloworld");
}
public void OnNotify(SDKMessageID MsgID, object pParam)
{
if (MsgID == SDKMessageID.NOTIFY_OFFLINE)
{
}
else if (MsgID == SDKMessageID.NOTIFY_USERLOGIN)
{
}
}
public void OnUninstall()
{
}
public void Require()
{
}
}
[ComVisible(true),
Guid("950BFC6C-502A-4239-A36E-90893BA3B03E"),
ClassInterface(ClassInterfaceType.None)]
public class Class2 : ISDKPluginItem {
Form1 f1;
public void OnMenuClick(int lCmdID)
{
}
// 插件作为按钮出现时候得到点击后被调用
// 本例中此方法将在点击发生后得到调用
public void OnClick()
{
try
{
this.f1.Show();
}
catch(Exception ex)
{
this.f1 = new Form1();
this.f1.Show();
}
}
// 插件接入到插槽后得到通知
public void OnCreate(object pSlot, int hParentWnd, int lCookie)
{
}
// 插件在附属插槽被销毁时候得到通知
public void OnDestroy()
{
// 使用模态对话框可能导致异常
// MessageBox.Show("聊天对话框输入工具条插件被销毁", "csharp allinone plugin");
}
// 和插件项本身相关的消息通知
public void OnNotify(SDKItemNotifyID MsgIDD, object pParam)
{
}
// 当插件以窗口形式出现情况下,在父窗口发生变化情况下得到通知
public void OnSize(int cx, int cy)
{
}
}
}
下面代码是JSHelper窗体主程序,没什么意思。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace JSHelper
{
public partial class Form1 : Form
{
String path;
Form2 f2;
Form2 f3;
Form2 f4;
Form2 f5;
Form2 f6;
public Form1()
{
InitializeComponent();
this.path = Application.StartupPath;
this.webBrowser1.Url = new System.Uri(this.path + "\\plugins\\" + Global.appid + "\\src\\debugger.html", false);
}
private void ExamplesToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
System.Diagnostics.Process.Start("explorer", this.path + "\\plugins\\" + Global.appid + "\\src\\example\\");//+this.path
}
catch(Exception ex)
{
MessageBox.Show("请打开插件中的example目录.\n\n该目录的路径可能如下:\n" + this.path + "\\plugins\\" + Global.appid + "\\src\\example\\");
}
}
private void HideToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
}
private void ManualToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
this.f2.Show();
}
catch
{
this.f2 = new Form2("使用说明", new System.Uri(this.path + "\\plugins\\" + Global.appid + "\\src\\readme\\KingfishersManual.html"));
this.f2.Show();
}
}
private void AboutJSHelperToolStripMenuItem_Click(object sender, EventArgs e)
{
String[] info=new String[7];
info[0] = "Version:0.9.0";
info[1] = "Release Date:2008-11-17";
info[2] = "JSHelper是一款轻巧的Javascript调试工具,";
info[3] = "以旺旺插件形式发布在阿里软件平台,";
info[4] = "依赖于jzshmyt所写Kingfishers工具包。";
info[5] = "方便使用是我的唯一目的。";
info[6] = "Author : CharlesCui";
try
{
this.f3.Show();
}
catch
{
this.f3 = new Form2("关于--JSHelper", String.Join("", info, 0, info.Length));
this.f3.Show();
}
}
private void JavascriptlogToolStripMenuItem_Click(object sender, EventArgs e)
{
String[] info = new String[5];
info[0] = "Kingfishers是一个用javascript语言编写的,能够代替alert,在浏览器中连续输出客户端javascript脚本运行日志的工具。";
info[1] = "主要用于客户端脚本的分析和查错。";
info[2] = "GoogleCode:http://code.google.com/p/dewind/";
info[3] = "Download:http://dewind.googlecode.com/files/Kingfishers-1.0.rar";
info[4] = "Author : jzshmyt";
try
{
this.f4.Show();
}
catch
{
this.f4 = new Form2("关于--Kingfishers", String.Join("", info, 0, info.Length));
this.f4.Show();
}
}
private void AboutAuthorToolStripMenuItem_Click(object sender, EventArgs e)
{
String[] info = new String[4];
info[0] = "作者博客:http://charlescui.javaeye.com";
info[1] = "作者邮箱:zheng.cuizh@gmail.com";
info[2] = "作者寄语:欢迎广大爱好插件开发(阿里旺旺\\Android)、系统性能调优的朋友们骚扰我!";
info[3] = "作者MSN:cuizheng.hz@hotmail.com";
try
{
this.f5.Show();
}
catch
{
this.f5 = new Form2("关于--作者", String.Join("", info, 0, info.Length));
this.f5.Show();
}
}
private void ParamsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
this.f6.Show();
}
catch
{
this.f6 = new Form2("参数说明", new System.Uri(this.path + "\\plugins\\" + Global.appid + "\\src\\readme\\KingfishersManual.txt"));
this.f6.Show();
}
}
}
}
下面代码是JSHelper实现页面的html:
"Content-Type" content="text/html; charset=UTF-8" />

