Struts2.0标签库(三)表单标签

来源:互联网 发布:诺基亚e63怎样下载软件 编辑:程序博客网 时间:2024/05/02 01:53

转自:http://www.blogjava.net/hhhaaawwwkkk/archive/2008/10/27/236925.html

Struts2.0标签库(三)表单标签

一、表单标签的通用属性
对于表单标签,分为两种标签:form标签本身,和所有来包装单个的表单元素的其他标签.form标签本身的行为不同于它内部的元素,这是很重要的.在我们为所有表单标签,包括form标签在内,提供一个参考手册之前,我们必须先描述一些通用的属性.

通用属性

属性Theme数据类型描述cssClasssimpleString定义 html class 属性cssStylesimpleString定义html style 属性titlesimpleString定义html title 属性disabledsimpleString定义html disabled 属性labelxhtmlString定义表单元素的labellabelPositionxhtmlString定义表单元素的label位置(top/left),缺省为leftrequiredpositionxhtmlString定义required 标识相对label元素的位置 (left/right),缺省是 rightnamesimpleString表单元素的name映射requiredxhtmlBoolean在label中添加 * (true增加,否则不增加)tabIndexsimpleString定义html tabindex 属性valuesimpleObject定义表单元素的value

模板相关属性

属性Theme数据类型描述templateDirn/aString定义模板目录themen/aString定义theme名称templaten/aString定义模板名称

Javascript相关属性

属性Theme数据类型描述onclicksimpleStringhtml javascript onclick 属性ondbclicksimpleStringhtml javascript ondbclick 属性onmousedownsimpleStringhtml javascript onmousedown 属性onmouseupsimpleStringhtml javascript onmouseup 属性onmouseoversimpleStringhtml javascript onmouseover 属性onmouseoutsimpleStringhtml javascript onmouseout 属性onfocussimpleStringhtml javascript onfocus 属性onblursimpleStringhtml javascript onblur 属性onkeypresssimpleStringhtml javascript onkeypress 属性onkeyupsimpleStringhtml javascript onkeyup 属性onkeydownsimpleStringhtml javascript onkeydown 属性onselectsimpleStringhtml javascript onselect 属性onchangesimpleStringhtml javascript onchange 属性

Tooltip 相关属性

属性数据类型缺省值描述tooltipStringnone设置此组件的tooltiptooltipIconString/webwork/static/tooltip/tooltip.giftooltip图标的urltooltipAboveMousePointerBooleanfalse在鼠标光标位置上放置tooltip.另外设置 tooltipOffseY 允许你设置从鼠标光标位置的垂直位移.tooltipBgColorString#e6ecfftooltip的背景色.tooltipBgImgStringnone背景图片.tooltipBorderWidthString1tooltip边框的宽度.tooltipBorderColorString#003399tooltip边框的背景色tooltipDelayString500显示Tooltip的时间延迟(毫秒). 类似基于操作系统的tooltip的行为.tooltipFixCoordinateXStringnot specified固定tooltip在指定的X坐标上.例如和tooltipSticky属性结合时很有用.tooltipFixCoordinateYStringnot specified固定tooltip在指定的Y坐标上.例如和tooltipSticky属性结合时很有用.tooltipFontColorString#000066字体颜色.tooltipFontFaceStringarial,helvetica,sans-serif字体,例如 verdana,geneva,sans-seriftooltipFontSizeString11px字体大小,例如 30pxtooltipFontWeightStringnormalFont weight. 可以是 normal 或者 boldtooltipLeftOfMousePointerBooleanfalse在鼠标光标位置左侧的Tooltip位置tooltipOffsetXString12相对鼠标光标位置的水平位移.tooltipOffsetYString15相对鼠标光标位置的垂直位移.tooltipOpacityString100tooltip的透明度. 不透明度是行对透明度而言的.设置的值必须是一个介于0(完全透明)和100(不透明)之间的数字.Opera尚未支持.tooltipPaddingString3内部间隔,例如,边框和内容之间的空格,例如文字或者图片tooltipShadowColorString#cccccc使用指定的颜色创建阴影.tooltipShadowWidthString5使用指定的宽度(距离)创建阴影.tooltipStaticBooleanfalse就像基于操作系统的tooltip, tooltip不随着鼠标光标移动而移动.tooltipStickyBooleanfalsetooltip一直停留在它初始的位置,直到另外一个tooltip被激活,或者用户点击了文档.tooltipStayAppearTimeString0指定一个tooltip消失的时间间隔(毫秒),即时鼠标还在相关的HTML元素上不懂,设置<=0,就和没有定义一样.tooltipTextAlignStringleft调整包括标题和tooltip内容的文字位置.可以是right, left 或 justifytooltipTitleStringnone标题tooltipTitleColorString#fffffftitle文字的颜色tooltipWidthString300tooltip的宽度二、表单标签
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"/>
结果:

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"/>

3、combobox(组合框)
combobox标签生成一个单行文本框和下拉列表框的组合,但值对应一个请求参数。
<s:comboboxlabel="请选择您喜欢的图书" theme="css_xhtml" labelposition="top"
            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"/>
结果:



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>
结果:



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>
结果:











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"/>
结果:
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>
结果:

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"/>
结果:
             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(日历控件)
<s:datetimepickername="order.date" label="购买日期" toggleType="explode" value="today"/>
结果:
Select a date
↓↓↑↑十月 日一二三四五六2829301234567891011121314151617181920212223242526272829303112345678

2007年2008年2009年

 
0 0
原创粉丝点击