jqGrid使用multipleSearch产生的查询条件filters分析

This is a tutorial that shows how to handle a JSON Object that is received in a Struts2 Action. This Example is based on the Struts2 Grid Showcase for the Struts2 jQuery Plugin with Grid Extension.
1). First we need to enable the Multi Search Feature for the Grid Component.
< sjg :grid 
	id="customerstable" 
	...
	navigatorSearch="true"
	navigatorSearchOptions="{multipleSearch:true}"
	...
>
Now we can use the multiple search feature like this. struts2 jquery grid with multiple search
2.) After this we need a String property filter in our Struts2 Action.
private String filters;
 
public void setFilters(String filters) {
 this.filters = filters;
}
3.) Now we receive a JSON Object when we use the Search in the Navigator of the Grid. The JSON looks like this example.
{
	"groupOp":"AND",
	"rules":[
		{
			"field":"customernumber",
			"op":"lt",
			"data":"200"
		}
		,
		{
			"field":"country",
			"op":"eq",
			"data":"USA"
		}
		]
}
4.) To work with this, we need to serialize this as a JSONObject.
JSONObject jsonFilter = (JSONObject) JSONSerializer.toJSON( filters );
5.) Now we can get the value from the JSON Object. First we get the parameter groupOp.
String groupOp = jsonFilter.getString("groupOp");
log.debug("groupOp :" + groupOp);
6.) Now we need the rules as JSONArray and the size of this array.
JSONArray rules = jsonFilter.getJSONArray("rules");
int rulesCount = JSONArray.getDimensions(rules)[0];
log.debug("Count Rules :" + rulesCount);
7.) In a simple for-loop we can get the values of the rule.
for (int i = 0; i < rulesCount; i++) {
	JSONObject rule = rules.getJSONObject(i);
	log.debug("field :" + rule.getString("field"));
	log.debug("op :" + rule.getString("op"));
	log.debug("data :" + rule.getString("data"));
}

Now you should be able to use this values to build a custom SQL query or build an hibernate criteria.

http://code.google.com/p/struts2-jquery/wiki/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值