struts2传递List对象(复合对象)
1、前台jsp界面:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@include file="../include/taglib.jsp"%>
<!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">
<title>Insert title here</title>
<script src="js/common/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
//对每行的第一个复选框实现简单的单选
$("#tablelist input[name=goodscheck]").click(function(){
$("#tablelist input[name=goodscheck]").attr('checked',false);
$(this).get(0).checked=true;
});
//添加一行,就是将第一个tr复制,默认有一个tr
$("#addbtn").click(function(){
var tr =$("#tablelist tr").eq(0);
var temptr=$(tr).clone(true); //复制tr
$("input",temptr).val(''); //将tr下的值清空
$("#tablelist").append(temptr);
});
//删除一行,至少有两个tr才能删除
$("#delbtn").click(function(){
if($("#tablelist tr").length>1){
var checks = $("#tablelist input[name=goodscheck]:checked");
if(checks && checks.length==1){
$(checks).parent().parent().remove();
}
}
});
//提交表单
$("#submit").click(function(){
refresh('tablelist');
testForm.submit();
});
});
//后台接收的是数组,因此需要刷新数组的索引值。如果刷新提交的索引为userTests[0]和userTests[2](假如userTests[1]被删除),
//后台的List集合的大小为3,索引为1的对象被认为是null.
function refresh(jq){
$("#"+jq+" tr").each(function(j){
$(this).children('td').children('input').each(function(){
var curname = $(this).attr('name');
if(curname){
var curnamearr = curname.split(".") ;
if(curnamearr && curnamearr.length>1){
var val="";
for(var i=1;i<curnamearr.length;i++){
val+="."+curnamearr[i];
}
$(this).attr('name','userTests['+j+']'+val);
}
}
});
});
}
</script>
</head>
<body>
<s:form action="login/test.do" id='testForm'>
<table id="tablelist">
<tr>
<td><input type="checkbox" name="goodscheck"></td>
<td><input type="text" name="userTests[0].name"/></td>
<td><input type="text" name="userTests[0].jtCode"/></td>
<td><input type="text" name="userTests[0].code"/></td>
<td><input type="text" name="userTests[0].operator.code"/></td>
</tr>
</table>
<s:submit id="submit" value="提交"></s:submit>
</s:form>
<br>
<input type="button" id="addbtn" value="添加">
<input type="button" id="delbtn" value="删除">
</body>
</html>
2、后台action代码:
private List<UserTest> userTests; //get set方法省略
public void test() {
if (userTests!=null) {
for(UserTest userTest: userTests){
logger.info(" ============ "+userTest +" operator: "+userTest.getOperator().getCode());
}
}else{
logger.info(" ============ userTest is null ");
}
}
3、javaBean对象
public class UserTest {
private String name;
private String code;
private String jtCode;
private TBLOperator operator;
...get set
}
public class TBLOperator implements Serializable {
private String code;
}
4、测试数据:
13:23:21,524 INFO [LoginAction] ============ UserTest [name=1, code=, jtCode=, operator=com.cjonline.foundation.evisa.entity.TBLOperator@1225261] operator: 11
13:23:21,524 INFO [LoginAction] ============ UserTest [name=2, code=, jtCode=, operator=com.cjonline.foundation.evisa.entity.TBLOperator@355104] operator: 22
13:23:21,524 INFO [LoginAction] ============ UserTest [name=4, code=, jtCode=, operator=com.cjonline.foundation.evisa.entity.TBLOperator@59e5ec] operator: 44444444
13:23:21,524 INFO [LoginAction] ============ UserTest [name=5, code=, jtCode=, operator=com.cjonline.foundation.evisa.entity.TBLOperator@5f77e] operator: 5555555555
struts2传递List对象(复合对象)的更多相关文章
- Activity之间传递数据或数据包Bundle,传递对象,对象序列化,对象实现Parcelable接口
package com.gaojinhua.android.activitymsg; import android.content.Intent; import android.os.Bundle; ...
- 3ds max学习笔记-- 复合对象运算
1,ProBoolean(超级布尔) 栗子: 新建一长方体,两个圆柱体,如下: 选择底部长方体,进入[复合对象],修改[操作],单击[拾取操作对象B],点击圆柱: 效果如下,线面较多: 高级布尔效果图 ...
- mybatis由浅入深day01_ 7输入映射(7.1传递pojo的包装对象_7.2#{}与${}_7.3传递简单类型_7.4传递pojo对象_7.5传递hashmap)
7 输入映射 通过parameterType指定输入参数的类型,类型可以是简单类型.hashmap.pojo的包装类型. 7.1 传递pojo的包装对象 7.1.1 需求 完成用户信息的综合查询,需要 ...
- [Objective-C语言教程]复合对象(33)
在Objective-C中,可以在类集群中创建子类,该类集合定义了一个嵌入在其中的类. 这些类对象是复合对象.你可能想知道什么是类集群,下面首先了解什么是类集群. 1. 类集群 类集群是基础框架广泛使 ...
- Intent之对象传递(Parcelable传递对象和对象集合)
接着上一篇文章,以下我们讨论一下怎样利用Parcelable实现Intent之间对象的传递 一.实现对象传递 首先创建User.java实现Parcelable接口: package org.yayu ...
- MVC传递数据-传递对象或对象集合
前言 本文主要介绍从View(或者js)文件向Controller提交对象或者对象集合.比方.将表格中的一行数据作为一个对象提交.或将多行数据作为一个集合提交到Controller. 回想 从View ...
- JSP内置对象--request对象
本文主要介绍JSP中的request对象 request对象的主要方法: setAttribute(String name,Object):设置名字为name的request的参数值 getAttri ...
- O-C相关-06:对象与对象的关系
对象与对象的关系 1.对象与对象的关系 依赖 关联 组合 常常讨论对象与对象关系时会提供两个属于:内聚性,耦合性 内聚一般指功能上的指向性 耦合一般指关联上的依赖性 2.依赖: 对象之间最弱的一种关联 ...
- Django运算表达式与Q对象/F对象
Django运算表达式与Q对象/F对象 1 模型查询 概述: 1 查询集:表示从数据库中获取的对象的集合 2 查询集可以有多个过滤器,通过 逻辑运算符连接 3 过滤器就是一个函数,基于所给的参数限制查 ...
- js中对象和对象创建方法
这一次我们来说一说在JavaScript中经常会用到的一个复杂基本类型,对象,先从对象的属性讲起,再讲对象的创建方法,基本涵盖了创建对象的各种方法,大家一起学习呀~ 一.对象 要掌握对象的使用及继承, ...
随机推荐
- flex 4 Filters
<s:RectangularDropShadow id="dropShadow" blurX="10" blurY="10" alph ...
- [HDOJ5667]Sequence(矩阵快速幂,费马小定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5667 费马小定理: 假如p是质数,且gcd(a,p)=1,那么 a^(p-1)≡1(mod p). 即 ...
- C# WebBrowser 设置代理完全解决方案
微软webbrowser控件也就是IE插件,他的所有功能就像IE类似,当然设置也是一样的,下面介绍下webbrowser如何设置代理,可不要用这个对抗广告联盟哦 You can change the ...
- CSS处理溢出
如果内容超过的区块的大小,内容就会溢出,可以使用下面的方法控制溢出 overflow visible 不剪切内容也不添加滚动条 auto 在必需时对象内容才会被裁切或显示滚动条 hidden 不显示超 ...
- 连接mongo的服务提示:HTTP Status 500 - com.mongodb.MongoException$Network: can't call something
连接mongo的服务提示以下错误 原因:达到了mongodb启动时预设的最大连接数,无法创建新的连接 HTTP Status 500 - com.mongodb.MongoException$Netw ...
- jquery 连写注释;siblings() 方法;jQuery 的3种滑动方法;slideUp()向上滑动;slideDown()向下滑动;slideToggle()来回滑动
首先我们看两个连写注释 第一个: /* 点击头像,显示基本资料 */ $(".f-chatTit a.avatar").click(function(){ $(this).hi ...
- impersonate a user
// This sample demonstrates the use of the WindowsIdentity class to impersonate a user. // IMPORTANT ...
- S2sh整合MAven项目所需坐标大全
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> & ...
- Hive 中函数总结
Hive supports three types of conditional functions. These functions are listed below: IF( Test Condi ...
- centos 6.5 minimal 安装及vm-tools安装
安装vm-->注册vm-->新建一个虚拟机(选择等会安装系统)-->加载iso-->配置桥接-->启动 这里可能碰到一个cpu的虚拟化配置,需要在bios里的配置设置为e ...