社区
Web 开发
帖子详情
标签的属性是什么含义
wafeng
2004-10-14 11:42:22
看了书上写的,几乎要晕了。什么呀,谁能给点资料
...全文
445
4
打赏
收藏
<html:options>标签的属性是什么含义
看了书上写的,几乎要晕了。什么呀,谁能给点资料
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
truediego
2005-06-14
打赏
举报
回复
mark
popufig
2004-10-15
打赏
举报
回复
给个具体的例子:
<%
Vector colorCollection = new Vector();
colorCollection.add(
new org.apache,struts.util.LabelValueBean("Pink","htmlselect.pink"));
colorCollection.add(
new org.apache,struts.util.LabelValueBean("Brown","htmlselect.brown"));
%>
......
<html:select ......>
<html:options collection="colorCollection " property="value" labelProperty="label"/>
</html:select>
LabelValueBean有两个属性:label和value,就是上面的label:Pink ;value:htmlselect.pink
而html:options 的property就是我们选中某条时setter进form的值
dlglmf
2004-10-15
打赏
举报
回复
表示多个列表元素,是一个集合,可以用vector或Arraylist等表示,但是,必须要用struts提供的labelValueBean(不知道名字对否,记得不太清楚),也就是把值放在上面的bean 里,然后在保存在集合里,显示可以是labelvaluebean 的label值也可以是value值
cold_blooded
2004-10-15
打赏
举报
回复
html:options是Struts中比较复杂的一个tage lib,用法灵活,但是Sturts提供的源码exercise taglib中没有提出常用jsp+ActionForm这样形式的最直接的总结,现从中总结如下,分两种情况:数组和Collection。
需求,要达到:
<select name="beanCollectionSelect" multiple="multiple" size="10"><option value="Value 0">Label 0</option><option value="Value 1" selected="selected">Label 1</option><option value="Value 2">Label 2</option><option value="Value 3" selected="selected">Label 3</option><option value="Value 4">Label 4</option><option value="Value 5" selected="selected">Label 5</option><option value="Value 6">Label 6</option><option value="Value 7">Label 7</option><option value="Value 8">Label 8</option><option value="Value 9">Label 9</option></select>
要实现上述效果,需要两步:
第一:设置ActionForm,
也分两小步:第一小步必须在ActionForm中,有一句
private Collection beanCollection;
public Collection getBeanCollection();
Collection beanCollection要确保是一个实现,如ArrayList,如果不是则会报No collection found的错误,Struts的最大不方便就是一旦出问题,定位很难,不知道什么地方使用错误,或忘记设置什么了。
因为前面需求中option的value值和label值不一样,那么在beanCollection中保存的就是一个value和label组成的对象,名为LabelValueBean,在LabelValueBean中有两个属性value和label,
在程序某个地方要为beanCollection赋值,如:
Vector entries = new Vector(10); entries.add(new LabelValueBean("Label 0", "Value 0")); entries.add(new LabelValueBean("Label 1", "Value 1")); entries.add(new LabelValueBean("Label 2", "Value 2")); entries.add(new LabelValueBean("Label 3", "Value 3")); entries.add(new LabelValueBean("Label 4", "Value 4")); entries.add(new LabelValueBean("Label 5", "Value 5")); entries.add(new LabelValueBean("Label 6", "Value 6")); entries.add(new LabelValueBean("Label 7", "Value 7")); entries.add(new LabelValueBean("Label 8", "Value 8")); entries.add(new LabelValueBean("Label 9", "Value 9"));
然后执行setBeanCollection(entries);
这样ActionForm中的beanCollection算有值了。
第二小步,需要设置Selected,selected有两种,单选和多选:
在ActionForm中必须有:
private String singleSelect = "Single 5"; public String getSingleSelect() { return (this.singleSelect); } public void setSingleSelect(String singleSelect) { this.singleSelect = singleSelect; }
或多选,多选必须是数组:
private String[] beanCollectionSelect = { "Value 1", "Value 3", "Value 5" }; public String[] getBeanCollectionSelect() { return (this.beanCollectionSelect); } public void setBeanCollectionSelect(String beanCollectionSelect[]) { this.beanCollectionSelect = beanCollectionSelect; }
第二:在Jsp中写入tang lib语句如下:
<html:select property="beanCollectionSelect" size="10" multiple="true"> <html:optionsCollection name="testbean" property="beanCollection"/> </html:select>
其中testbean是ActionForm的名称。
以上是html:options的Collection解决方案,如果option值很少,简单地可以实现为数组,两步:
第一:在ActionForm中,
private String values[] = { "Magazine", "Journal", "News Paper","Other" }; private String labels[] = { "L-Magazine", "L-Journal", "L-News Paper","L-Other"}; private String selected = "Magazine"; public String getSelected(){ return selected; } public void setSelected(String selected){ this.selected = selected; } public String[] getValues(){ return values; } public void setValues(String[] values){ this.values = values; } public String[] getLabels(){ return values; } public void setLabels(String[] labels){ this.labels = labels; }
第二步在jsp中:
<html:select property="selected" > <html:options name="testbean" property="values" labelProperty="label"/> </html:select>
jsp中
html
select
标签
的用法
html
:select>
标签
的用法
HTML
select option基础理解及使用
javascript之
HTML
(select option)详解 一、基础理解: 复制代码代码如下: var e = document.getElementById(“selectId”); e.
options
= new Option(“文本”,”值”) ; //创建一个option对象,即在<select>
标签
中创建一个或多个
文本
//
options
是个数组,里面可以存放多个
文本
这样的
标签
1:
options
[ ]数组的
属性
: length
属性
———长度
属性
selectedIn
java表单中下拉菜单怎么写_SpringWeb
options>
标签
:定义下拉选择框或列表框的多个选项...
该
标签
是
标签
的子
标签
,用于定义表单的下拉选择框或列表框的多个选项。语法:参数说明:items:选项的提示信息。itemValue:选项的值。itemLabel:选项的值。示例1使用 Spring Web
标签
实现在页面中添加下拉列表。在 Fans 类中定义 fanList
属性
,模拟一个控制器的表单对象,关键代码如下:public class Fans{List fanList = new A...
<
html
:select>,<
html
:option>,<
html
:
options
Collection>和<
html
:
options
>的区别
生成
HTML
元素 :生成
HTML
元素 :生成一组
HTML
元素 生成一组
HTML
元素。 生成
HTML
元素,表示下拉列表框或多选列表。 [color=red]在
标签
中可以包含多个,,元素。[/color]
标签
有以下重要
属性
size
属性
:指定每次在网页上显示的可选项的数目。 multipe
属性
:指定是否支持多项选择,如果设置为true,就表示多选列表,支持...
SpringMVC
表单
标签
和
表单
标签
简介
表单相关问题介绍
Web 开发
81,091
社区成员
341,718
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章