我们会经常遇到需要选取一行然后去查看这行数据的详细情况所以:
jquery
$('#look').bind("click",function(){
*var trIds = getSelectedTrIds();*//jq专业方法获取获取焦点的一行的Id集合
*var trs = getSelectedTrs();*//jq专业方法获取获取焦点的一行
if(checkRecordSize(trIds,true)){ window.location.href="${basePath}/log/deviceFlowAnalyseLogAction_checkDetailedContentUI.do?serverSoftId="+trs[0].serverSoftId; //showWindow($(this).attr("title"),"${basePath}/log/deviceFlowAnalyseLogAction_checkDetailedContentUI.do?ids="+trIds[0],570,435,true);
};
});
这是非常简单的一段js,表示点击某一行会把哪一行(一个对象)的某个属性给带到下个页面中()(checkDetailedContentUI.do)这里的do是struts的表示方法,相当于一种转接,现在我们来看看action中是怎么写的
“`java
public String checkDetailedContentUI(){
String serverSoftId=getRequest().getParameter(“serverSoftId”);
getRequest().setAttribute(“serverSoftId”, serverSoftId);
return “checkDetailedContentUI”;
}
####这里所做的操作就是将页面所带出来的参数传到本来要去的y页面,放在request是最好取得的,那我们来看看我们要去的那个页面是怎么写url的
```jquery
$('#inside_tableElement').datagrid({ url:"${basePath}/log/deviceFlowAnalyseLogAction_getServerSoftStateLogJson.do?queryBean1.serverSoftId=<s:property value='#request.serverSoftId'/>",
striped: true,
collapsible:true,
frozenColumns:[[
{field:'ck',checkbox:true}
]],
columns:[[
{field:'id',title:'ID',hidden :true}
<s:iterator value="#application.vrvSysTablesAttr['ServerSoftStateLog'].columns">
<s:if test='isList.name =="Y" '>
<s:if test='key == "state"'>
,{field:'<s:property value="key"/>',title:'<s:text name="%{name}" />',align:'center'
,formatter: function(value,row,index){
var international= getCemsColumns(sText_Json,this.field,value);
return international;
}
}
</s:if>
<s:else>
,{field:'<s:property value="key"/>',title:'<s:text name="%{name}" />'
,formatter: function(value,row,index){
var international= getCemsColumns(sText_Json,this.field,value);
return international;
}
}
</s:else>
</s:if>
</s:iterator>
]],
onLoadSuccess:function getData(data){
console.log(data);
return data;
},
pagination:true,
rownumbers:true,
fitColumns:getColumnShowType(),
fitColumns:false,
onLoadSuccess: function (data) {getrate();},
onHeaderContextMenu: function(e, field){
headerContextMenu(e,field);
}
});
<div class="se-preview-section-delimiter"></div>
看到没url后面是这样接受上个页面所传递过来的参数的并放在了这个项目的查询参数里面querybean,当然这个参数也不会闲着
“`
public void getServerSoftStateLogJson()throws InvocationTargetException{
List dataList=null;
Page page = null;
String orderStr = getRequest().getParameter(“order”);
String sortStr = getRequest().getParameter(“sort”);
if (queryBean1 == null) {
queryBean1 = new ServerSoftStateLogQueryBean();
}
if (sortStr != null && orderStr != null) {
String[] orderArr = orderStr.split(“,”);
String[] sortArr = sortStr.split(“,”);
for (int i = 0; i < sortArr.length; i++) {
queryBean.addOrderProperty(“this.” + sortArr[i],
“asc”.equals(orderArr[i]) ? Order.ASC : Order.DESC);
}
}
page = serverSoftStateLogService.query(queryBean1, getCurrentPageNo(), getPageSize());
dataList=page.getDataList();
log.info("获取dataList-END");
/* dataList=page(dataList, getCurrentPageNo(), getPageSize());*/
JsonConfigEx jsonConfigEx = new JsonConfigEx();
String json = JsonUtils.collection2Json(dataList,jsonConfigEx);
//将riskLevel,behaviourType,a三个字段名和对应的字段值加入此要传到页面的json中
JSONArray jsonArr=JSONArray.fromObject(json);
JSONArray jsonArrN=new JSONArray();
if (jsonArr!=null) {
for (int i = 0; i < jsonArr.size(); i++) {
try {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd kk:mm:ss ");
JSONObject jsonObj = jsonArr.getJSONObject(i);
LogServer logServer =logServerService.queryByStringId(jsonObj.getString("serverId"));
jsonObj.put("ip", logServer!=null?logServer.getIp():"");
LogServerArea logServerArea=logServerAreaService.queryByStringId(logServer.getServerAreaId());
jsonObj.put("areaName", logServerArea!=null?logServerArea.getName():"");
LogServerSoftState logServerSoftState=logServerSoftStateService.queryByServerSoftId(jsonObj.getString("serverSoftId"));
jsonObj.put("syncTime", logServerSoftState!=null?sdf.format(logServerSoftState.getSyncTime()):"");
jsonArrN.add(jsonObj);
} catch (Exception e) {
// TODO: handle exception
}
}
}else{
jsonArrN = jsonArr;
}
int total = 0;
if (page != null) {
String ob = getSession().getAttribute("selectStyle").toString();
if("1".equals(ob)){
total = page.getTotalDataCount();
}else{
total = page.getTotalPageCount();
}
}
getSession().setAttribute("json", jsonArrN.toString());
//---------------------------------数据过滤END
String girdJson = EasyUIGridUtils.toGridJson(total, jsonArrN.toString());
print(girdJson);
log.info("列表查询-END");
}
“`
看到没url后面是这样接受上个页面所传递过来的参数的并放在了这个项目的查询参数里面querybean,当然这个参数也不会闲着
“`java
public void getServerSoftStateLogJson()throws InvocationTargetException{
List dataList=null;
Page page = null;
String orderStr = getRequest().getParameter(“order”);
String sortStr = getRequest().getParameter(“sort”);
if (queryBean1 == null) {
queryBean1 = new ServerSoftStateLogQueryBean();
}
if (sortStr != null && orderStr != null) {
String[] orderArr = orderStr.split(“,”);
String[] sortArr = sortStr.split(“,”);
for (int i = 0; i < sortArr.length; i++) {
queryBean.addOrderProperty(“this.” + sortArr[i],
“asc”.equals(orderArr[i]) ? Order.ASC : Order.DESC);
}
}
page = serverSoftStateLogService.query(queryBean1, getCurrentPageNo(), getPageSize());
dataList=page.getDataList();
log.info("获取dataList-END");
/* dataList=page(dataList, getCurrentPageNo(), getPageSize());*/
JsonConfigEx jsonConfigEx = new JsonConfigEx();
String json = JsonUtils.collection2Json(dataList,jsonConfigEx);
//将riskLevel,behaviourType,a三个字段名和对应的字段值加入此要传到页面的json中
JSONArray jsonArr=JSONArray.fromObject(json);
JSONArray jsonArrN=new JSONArray();
if (jsonArr!=null) {
for (int i = 0; i < jsonArr.size(); i++) {
try {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd kk:mm:ss ");
JSONObject jsonObj = jsonArr.getJSONObject(i);
LogServer logServer =logServerService.queryByStringId(jsonObj.getString("serverId"));
jsonObj.put("ip", logServer!=null?logServer.getIp():"");
LogServerArea logServerArea=logServerAreaService.queryByStringId(logServer.getServerAreaId());
jsonObj.put("areaName", logServerArea!=null?logServerArea.getName():"");
LogServerSoftState logServerSoftState=logServerSoftStateService.queryByServerSoftId(jsonObj.getString("serverSoftId"));
jsonObj.put("syncTime", logServerSoftState!=null?sdf.format(logServerSoftState.getSyncTime()):"");
jsonArrN.add(jsonObj);
} catch (Exception e) {
// TODO: handle exception
}
}
}else{
jsonArrN = jsonArr;
}
int total = 0;
if (page != null) {
String ob = getSession().getAttribute("selectStyle").toString();
if("1".equals(ob)){
total = page.getTotalDataCount();
}else{
total = page.getTotalPageCount();
}
}
getSession().setAttribute("json", jsonArrN.toString());
//---------------------------------数据过滤END
String girdJson = EasyUIGridUtils.toGridJson(total, jsonArrN.toString());
print(girdJson);
log.info("列表查询-END");
}
```
当时这个参数已经进入了这个querybean了,也就是已经传到action中了