Struts2.0标签库(三)表单标签
来源:互联网 发布:诺基亚e63怎样下载软件 编辑:程序博客网 时间:2024/05/02 01:53
转自:http://www.blogjava.net/hhhaaawwwkkk/archive/2008/10/27/236925.html
Struts2.0标签库(三)表单标签
一、表单标签的通用属性对于表单标签,分为两种标签:form标签本身,和所有来包装单个的表单元素的其他标签.form标签本身的行为不同于它内部的元素,这是很重要的.在我们为所有表单标签,包括form标签在内,提供一个参考手册之前,我们必须先描述一些通用的属性.
通用属性
模板相关属性
Javascript相关属性
Tooltip 相关属性
1、checkbox(复选框)
struts2的checkbox标签在使用的时候需要注意它的两个属性。value和fieldValue,在其他的标签中value是真实值。而在checkbox中,value如果为true,就表示复选框被选中;如果为false就表示不被选中。fieldValue才是此复选框对应的真实的值。
<s:checkbox name="xingming" value="false" fieldValue="aaaaa" label="value=false"/>
<s:checkbox name="xingming" value="true" fieldValue="aaaaa" label="value=true"/>
结果:<s:checkbox name="xingming" value="true" fieldValue="aaaaa" label="value=true"/>
2、checkboxlist(复选框组)
<s:checkboxlistname="a" label="请选择您喜欢的图书" labelposition="top"
list="{'struts2.0','hibernate','spring'}"/>
<!--用Map对象生成多个复选框-->
<s:checkboxlistname="b" label="请选择您喜欢的图书" labelposition="top"
list="#{'struts2.0':'2006/10','hibernate':'2007/8','spring':'2008/9'}"
listKey="key" listValue="value"/>
list="{'struts2.0','hibernate','spring'}"/>
<!--用Map对象生成多个复选框-->
<s:checkboxlistname="b" label="请选择您喜欢的图书" labelposition="top"
list="#{'struts2.0':'2006/10','hibernate':'2007/8','spring':'2008/9'}"
listKey="key" listValue="value"/>
3、combobox(组合框)
combobox标签生成一个单行文本框和下拉列表框的组合,但值对应一个请求参数。
<s:comboboxlabel="请选择您喜欢的图书" theme="css_xhtml" labelposition="top"
list="{'struts2.0','hibernate','spring'}" size="20" maxlength="20" name="book"/>
结果:list="{'struts2.0','hibernate','spring'}" size="20" maxlength="20" name="book"/>
4、select(下拉菜单)
<s:selectlabel="请选择您喜欢的书籍"
labelposition="top" name="books"
list="{'struts2.0','hibernate','spring','ajax'}"
multiple="true" size="2" required="true"/>
<s:select list="#{'struts':'aaaa','hibernate':'bbbb','spring':'cccc','ajax':'dddd'}"
listKey="key" listValue="value" label="选择你喜欢的作者" labelposition="top"
name="b"/>
结果:labelposition="top" name="books"
list="{'struts2.0','hibernate','spring','ajax'}"
multiple="true" size="2" required="true"/>
<s:select list="#{'struts':'aaaa','hibernate':'bbbb','spring':'cccc','ajax':'dddd'}"
listKey="key" listValue="value" label="选择你喜欢的作者" labelposition="top"
name="b"/>
5、doubleselect
doubleselect标签会生成一个级联列表框,当选择第一个下拉列表,第二个下拉框的内容也会随之改变。
<s:setname="bs"
value="#{'数据标签':{'action','bean','date','set'},
'控制标签':{'iterator','append','subset'},'表单标签':{'select','checkbox','radio'}}"/>
<s:form action="x">
<s:doubleselectlabel="请选择您喜欢的图书" labelposition="top" size="3"
name="author" list="#bs.keySet()" multiple="false"
doubleName="book" doubleList="#bs[top]" doubleMultiple="false"
doubleSize="3"/>
</s:form>
结果:value="#{'数据标签':{'action','bean','date','set'},
'控制标签':{'iterator','append','subset'},'表单标签':{'select','checkbox','radio'}}"/>
<s:form action="x">
<s:doubleselectlabel="请选择您喜欢的图书" labelposition="top" size="3"
name="author" list="#bs.keySet()" multiple="false"
doubleName="book" doubleList="#bs[top]" doubleMultiple="false"
doubleSize="3"/>
</s:form>
6、optiontransferselect
<s:optiontransferselect
doubleList="{'javaScript','ajax','sql'}"
list="{'struts2.0','hibernate','spring'}"
name="cnbook" doubleName="enbook"
addAllToLeftLabel="全部向左移" addAllToRightLabel="全部向右移"
addToLeftLabel="向左移" addToRightLabel="向右移"
allowAddAllToLeft="true" allowAddAllToRight="true"
allowAddToLeft="true" allowAddToRight="true"
allowUpDownOnLeft="true"allowUpDownOnRight="true"
multiple="true" doubleMultiple="true"
emptyOption="true" doubleEmptyOption="true"
headerKey="cnKey" doubleHeaderKey="enKey"
headerValue="--选择中文图书--" doubleHeaderValue="--choose English book--"
allowSelectAll="true" selectAllLabel="全部选中"
leftTitle="中文图书" rightTitle="Einglish books"
leftDownLabel="下移" rightDownLabel="下移"
leftUpLabel="上移" rightUpLabel="上移"
label="图书管理"
>
</s:optiontransferselect>
结果:doubleList="{'javaScript','ajax','sql'}"
list="{'struts2.0','hibernate','spring'}"
name="cnbook" doubleName="enbook"
addAllToLeftLabel="全部向左移" addAllToRightLabel="全部向右移"
addToLeftLabel="向左移" addToRightLabel="向右移"
allowAddAllToLeft="true" allowAddAllToRight="true"
allowAddToLeft="true" allowAddToRight="true"
allowUpDownOnLeft="true"allowUpDownOnRight="true"
multiple="true" doubleMultiple="true"
emptyOption="true" doubleEmptyOption="true"
headerKey="cnKey" doubleHeaderKey="enKey"
headerValue="--选择中文图书--" doubleHeaderValue="--choose English book--"
allowSelectAll="true" selectAllLabel="全部选中"
leftTitle="中文图书" rightTitle="Einglish books"
leftDownLabel="下移" rightDownLabel="下移"
leftUpLabel="上移" rightUpLabel="上移"
label="图书管理"
>
</s:optiontransferselect>
7、radio
<s:radioname="a" label="选择您喜爱的图书" labelposition="top"
list="'struts','hibernate','spring'"/>
<s:radio name="b" label="选择您喜爱的图书" labelposition="top"
list="#{'struts':'111','hibernate':'222','spring':'333'}"
listKey="key" listValue="value"/>
<s:bean name="com.zzn.books.BookService" id="bs"/>
<s:radio name="c" label="选择您喜爱的图书" labelposition="top"
list="#bs.books" listKey="name" listValue="author"/>
结果:list="'struts','hibernate','spring'"/>
<s:radio name="b" label="选择您喜爱的图书" labelposition="top"
list="#{'struts':'111','hibernate':'222','spring':'333'}"
listKey="key" listValue="value"/>
<s:bean name="com.zzn.books.BookService" id="bs"/>
<s:radio name="c" label="选择您喜爱的图书" labelposition="top"
list="#bs.books" listKey="name" listValue="author"/>
8、optgroup
optgroup标签用于生成一个下拉列表框的选项组,因此,该标签必须放在<s:select.../>标签中使用。
<s:selectname="book" label="选择你喜欢的作者" labelposition="top"
list="#{'struts':'aaaa','hibernate':'bbbb','spring':'cccc','ajax':'dddd'}"
listKey="key" listValue="value">
<s:optgroup label="Rod Johnson"
list="#{'aaaaaaaa':'bbbbbbbb'}"
listKey="key" listValue="value"/>
<s:optgroup label="David Flanagan"
list="#{'javaScript:The Definitive Guide':'David'}"
listKey="key" listValue="value"/>
</s:select>
结果:list="#{'struts':'aaaa','hibernate':'bbbb','spring':'cccc','ajax':'dddd'}"
listKey="key" listValue="value">
<s:optgroup label="Rod Johnson"
list="#{'aaaaaaaa':'bbbbbbbb'}"
listKey="key" listValue="value"/>
<s:optgroup label="David Flanagan"
list="#{'javaScript:The Definitive Guide':'David'}"
listKey="key" listValue="value"/>
</s:select>
9、token
这是一个防止多次提交表单的标签,能避免刷新页面时多次提交,如果要该标签起作用,应该在struts.xml中用TokenInterceptor拦截器或TokenSessionStoreInerceptor拦截器。
<s:tolen/>
10、head该标签主要用于生成HTML主要页面的HEAD部分。如果需要页面中有用Ajax组件,使用一个带theme=”ajax“属性的head标签,就可以将标准Ajax的头信息包含在页面中。
<s:headtheme="ajax"/>
11、updownselect<s:updownselectname="a" label="请选择您喜欢的图书" labelposition="top"
moveUpLabel="向上移动"
list="{'struts2.0','hibernate','spring'}"/>
<s:updownselectname="b" label="请选择您喜欢的图书" labelposition="top"
moveDownLabel="向下移动" selectAllLabel="全部选择"
list="#{'struts2.0':'2006/10','hibernate':'2007/8','spring':'2008/9'}"
listKey="key" listValue="value" emptyOption="true"/>
结果:moveUpLabel="向上移动"
list="{'struts2.0','hibernate','spring'}"/>
<s:updownselectname="b" label="请选择您喜欢的图书" labelposition="top"
moveDownLabel="向下移动" selectAllLabel="全部选择"
list="#{'struts2.0':'2006/10','hibernate':'2007/8','spring':'2008/9'}"
listKey="key" listValue="value" emptyOption="true"/>
12、actionerror和actionmessage
actionerror和actionmessage这两个标签用法完全一样,都是负责输出Action实例里封装的信息,区别是actionerror标签负责输出Action市里的getActionError()方法的返回值,而actionmessage标签负责输出Action实例的getActionMessage()的返回值。
13、tree和treenode初步
注意:用这个标签加上<s:head theme="ajax"/>
<s:treelabel="计算机图书" id="book" theme="ajax"
showRootGrid="true" showGrid="true" treeSelectedTopic="treeSelected">
<s:treenode label="张孝祥" id="zxx" theme="ajax">
<s:treenode label="java教程" id="java" theme="ajax"/>
<s:treenode label="javascript宝典" id="javascript" theme="ajax"/>
<s:treenode label="j2ee详解" id="j2ee" theme="ajax"/>
</s:treenode>
<s:treenode label="李刚" id="lg" theme="ajax">
<s:treenode label="struts2.0" id="struts" theme="ajax"/>
<s:treenode label="spring" id="spring" theme="ajax"/>
<s:treenode label="hibernate" id="hibernate" theme="ajax"/>
</s:treenode>
<s:treenode label="David" id="d" theme="ajax">
<s:treenode label="ajax" id="ajax" theme="ajax"/>
</s:treenode>
</s:tree>
13、datetimepicker(日历控件)showRootGrid="true" showGrid="true" treeSelectedTopic="treeSelected">
<s:treenode label="张孝祥" id="zxx" theme="ajax">
<s:treenode label="java教程" id="java" theme="ajax"/>
<s:treenode label="javascript宝典" id="javascript" theme="ajax"/>
<s:treenode label="j2ee详解" id="j2ee" theme="ajax"/>
</s:treenode>
<s:treenode label="李刚" id="lg" theme="ajax">
<s:treenode label="struts2.0" id="struts" theme="ajax"/>
<s:treenode label="spring" id="spring" theme="ajax"/>
<s:treenode label="hibernate" id="hibernate" theme="ajax"/>
</s:treenode>
<s:treenode label="David" id="d" theme="ajax">
<s:treenode label="ajax" id="ajax" theme="ajax"/>
</s:treenode>
</s:tree>
<s:datetimepickername="order.date" label="购买日期" toggleType="explode" value="today"/>
结果:十月 日一二三四五六2829301234567891011121314151617181920212223242526272829303112345678