Tuesday, December 09, 2008

 

option, options, optionsCollection

http://zhidao.baidu.com/question/13087595.html

Monday, December 08, 2008

 

jsp通过logic:iterate或html:optionsCollection循环显示action中传过来的对象List

http://www.blogjava.net/ec2008/archive/2007/09/15/145440.html

action中代码如下:
List allUser=this.getLoginServiceImpl().find();
request.setAttribute(
"user", allUser);
return mapping.findForward("listUser");
注:其中User对象有id和name属性

jsp显示:法一
<html:select property="school">
<html:option value="">
<bean:message key="login.select" />
html:option>
<logic:present name="user">
<logic:iterate id="user" name="user" offset="0">
<option value=""user" property="id" />">
<bean:write name="user" property="name" />
option>
logic:iterate>
logic:present>
html:select>
jsp显示:法二
<html:select property="school">
<html:optionsCollection name="user" value="id" label="name"/>
html:select>

optionsCollection标签用法:
与options标签一样,optionsCollection标签可以从集合或者是包含集合的对象里获得选项的标签/值对。在这两种情况里,集合或包含集合的对象必须是一个作用域对象,否则定制标签将无法访问它。

1.与包含集合的对象配合使用
举例:userForm动作表单有一个如下所示的ArrayList类型的userList属性,相应的set,get方法,通过在action中设置好userForm后,request.setAttribute("userForm",userForm);
在jsp页面:
<html:select property="school">
<html:optionsCollection name="userForm"
property
="userList"/>
html:select>

2.与集合配合使用
action中
ArrayList userList=new ArrayList();
userList.add(
new LabelValueBean("1","haha"));
userList.add(
new LabelValueBean("2","dada"));
userList.add(
new LabelValueBean("3","xiaoxiao"));
request.setAttribute(
"userList",userList);
jsp页面
<html:select property="school">
<html:optionsCollection name="userList"
label
="label" value="value"/>
html:select>

This page is powered by Blogger. Isn't yours?