octscorpion
BlogJava
::
首页
::
联系
::
聚合
::
管理
0 Posts :: 17 Stories :: 0 Comments :: 0 Trackbacks
留言簿
给我留言
查看公开留言
查看私人留言
我参与的团队
文章档案
2013年1月 (5)
2012年12月 (5)
2012年11月 (4)
2012年10月 (3)
搜索
最新评论
Struts2结合EasyUI的combobox返回json
前台页面:
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=UTF-8
"
pageEncoding
=
"
UTF-8
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=UTF-8"
>
<
script
type
="text/javascript"
src
="<%=request.getContextPath()%>/js/jquery-1.4.js"
></
script
>
<
link
rel
="stylesheet"
type
="text/css"
href
="<%=request.getContextPath()%>/css/easyui.css"
/>
<
script
type
="text/javascript"
src
="<%=request.getContextPath()%>/js/jquery.easyui.min.js"
></
script
>
<
title
>
EasyUI
</
title
>
</
head
>
<
body
>
<
input
class
="easyui-combobox"
name
="language"
data-options
="
url:'SRCEasyUI_combobox.do',
valueField:'key',
textField:'value',
multiple:true,
"
panelHeight:'auto'
>
</
body
>
</
html
>
Action方法:
package
jp.vacation.holiday.action;
import
java.util.ArrayList;
import
java.util.List;
import
jp.vacation.holiday.form.EasyUIForm;
import
net.sf.json.JSONArray;
import
net.sf.json.JSONObject;
import
org.springframework.context.annotation.Scope;
import
org.springframework.stereotype.Controller;
import
com.webpump.sdk.struts2.core.AbstractFwAction;
@Controller(
"
EasyUIAction
"
)
@Scope(
"
prototype
"
)
public
class
EasyUIAction
extends
AbstractFwAction
{
private
static
final
long
serialVersionUID
=
1L
;
private
JSONArray jsonArray;
public
JSONArray getJsonArray()
{
return
jsonArray;
}
public
void
setJsonArray(JSONArray jsonArray)
{
this
.jsonArray
=
jsonArray;
}
public
String combobox()
{
List
<
JSONObject
>
jsonList
=
new
ArrayList
<
JSONObject
>
();
for
(
int
i
=
0
; i
<
5
; i
++
)
{
EasyUIForm easyuiform
=
new
EasyUIForm();
easyuiform.setKey(
"
key
"
+
i);
easyuiform.setValue(
"
value
"
+
i);
JSONObject js
=
JSONObject.fromObject(easyuiform);
jsonList.add(js);
}
JSONArray jarray
=
JSONArray.fromObject(jsonList);
this
.jsonArray
=
jarray;
return
SUCCESS;
}
}
form类
package
jp.vacation.holiday.form;
public
class
EasyUIForm
{
private
String key;
private
String value;
public
String getKey()
{
return
key;
}
public
void
setKey(String key)
{
this
.key
=
key;
}
public
String getValue()
{
return
value;
}
public
void
setValue(String value)
{
this
.value
=
value;
}
}
Struts2 的xml配置
<!
DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"
>
<
struts
>
<
package
name
="vacation"
extends
="vacation_common"
>
<
result-types
>
<
result-type
name
="json"
class
="org.apache.struts2.json.JSONResult"
/>
</
result-types
>
<
action
name
="SRCEasyUI_combobox"
method
="combobox"
class
="EasyUIAction"
>
<
result
type
="json"
>
<!--
jsonArray必须在Action中定义,必须写它的get,set方法
-->
<
param
name
="root"
>
jsonArray
</
param
>
</
result
>
</
action
>
</
package
>
</
struts
>
combobox用的是json数组,json数组中放的是json对象
posted on 2013-01-08 17:13
一G刀客
阅读(3658)
评论(0)
编辑
收藏
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
Copyright @ 一G刀客
Powered by:
.Text
and
ASP.NET
Theme by:
.NET Monster