struts2中表现层的数据展现(bean,list,iterator,format,etc)

2014-11-24 10:36:17 · 作者: · 浏览: 0

假定在Action中通过get/set了绑定了一个ModelAndView 的bean,用于渲染页面的数据。在实际的开发中,这个bean可能包含了各种页面需要的信息,因此会相当复杂。

设定:bean mv

[java]
public class CompanyMV {
private Company company;
private List cities;
private List currencies;
private List moneystyles;
private List customers;
//.......

private File logofile;
private String logofileContentType;
private String logofileFileName;
//..get/set

}

1,遍历(iterator)

1.1) 包含html

[html]

Note: 此处通过设置cities的值到session, 为了防止表单验证之后的list值丢失。如果不通过也可使用在form中隐含变量的方式,eg
[html]

].id.qualityindex" value="" />
].qualityvalue" value="" />

此处的id是qualitys的复合primary key. (通过hibernate生成)

固定的list

[html]


1.2) 利用tag


[php]
name="mv.locid"
list="mv.floors"
listKey="locid"
listValue="shortdescription" />

1.3) 包含for循环的java代码


[html]

2,格式化(format)

2.1) 数字


[html] view plaincopy
name="mv.qualitys[].qualityvalue"
value=""
/>

Note:global.format.number.nopositionif在多语言资源文件中定义,eg
[html] view plaincopy
global.format.number.noposition={0,number,##########}
global.format.number.nopositionif={0,number,##########.##}
global.format.number.2position={0,number,##########.00}
global.format.date.normal={0,date,yyyy-MM-dd}


3,集合(List,Array,Set)的显示

直接看代码,仔细阅读,不解析

[html]



].officeid" value="" >
].suiteid" value="" />



].size" value="" onkeyup="java script:changeEstRent()">



].cost" value="" readonly>



].shortdescription" value="">



].longdescription" value="">



].workstation" value="">



].link" value="">





].crate" value="" />
].ncrate" value="" />
].arate" value="" />
].roomtype" value="" />




www.2cto.com


].targetrent" value="" readonly>