struts2.0标签技术简介

来源:互联网 发布:ipad刷windows系统教程 编辑:程序博客网 时间:2024/05/16 04:31

Converter表单标签的theme

 HTML标签(包括表单标签)都是模板驱动的.模板按照form的theme分组.struts2缺省提供了三种theme:  

  • simple
  • xhtml, 扩展了 simple (缺省theme)
  • css_html
  • ajax, 扩展了 xhtml
  • 使用simple theme的缺点就是它不支持其他theme那么多的属性.例如.label属性在simple theme里没有任何用处.类似的,simple theme提供的功能也远远少于xhtml和ajax theme提供的:自动显示错误信息就不被支持.

     

    通用的属性

    所有表单标签扩展了 UIBean 类.这个基类有一些通用属性,分为三种:模板相关的,javascript相关的和通用属性.

    模板相关属性

    属性 Theme 数据类型 描述 templateDir n/a String 定义模板目录 theme n/a String 定义theme名称 template n/a String 定义模板名称

    Javascript相关属性

    属性 Theme 数据类型 描述 onclick simple String html javascript onclick 属性 ondbclick simple String html javascript ondbclick 属性 onmousedown simple String html javascript onmousedown 属性 onmouseup simple String html javascript onmouseup 属性 onmouseover simple String html javascript onmouseover 属性 onmouseout simple String html javascript onmouseout 属性 onfocus simple String html javascript onfocus 属性 onblur simple String html javascript onblur 属性 onkeypress simple String html javascript onkeypress 属性 onkeyup simple String html javascript onkeyup 属性 onkeydown simple String html javascript onkeydown 属性 onselect simple String html javascript onselect 属性 onchange simple String html javascript onchange 属性

    Tooltip 相关属性

    属性 数据类型 缺省值 描述 tooltip String none 设置此组件的tooltip tooltipIcon String /webwork/static/tooltip/tooltip.gif tooltip图标的url tooltipAboveMousePointer Boolean false 在鼠标光标位置上放置tooltip.另外设置 tooltipOffseY 允许你设置从鼠标光标位置的垂直位移. tooltipBgColor String #e6ecff tooltip的背景色. tooltipBgImg String none 背景图片. tooltipBorderWidth String 1 tooltip边框的宽度. tooltipBorderColor String #003399 tooltip边框的背景色 tooltipDelay String 500 显示Tooltip的时间延迟(毫秒). 类似基于操作系统的tooltip的行为. tooltipFixCoordinateX String not specified 固定tooltip在指定的X坐标上.例如和tooltipSticky属性结合时很有用. tooltipFixCoordinateY String not specified 固定tooltip在指定的Y坐标上.例如和tooltipSticky属性结合时很有用. tooltipFontColor String #000066 字体颜色. tooltipFontFace String arial,helvetica,sans-serif 字体,例如 verdana,geneva,sans-serif tooltipFontSize String 11px 字体大小,例如 30px tooltipFontWeight String normal Font weight. 可以是 normal 或者 bold tooltipLeftOfMousePointer Boolean false 在鼠标光标位置左侧的Tooltip位置 tooltipOffsetX String 12 相对鼠标光标位置的水平位移. tooltipOffsetY String 15 相对鼠标光标位置的垂直位移. tooltipOpacity String 100 tooltip的透明度. 不透明度是行对透明度而言的.设置的值必须是一个介于0(完全透明)和100(不透明)之间的数字.Opera尚未支持. tooltipPadding String 3 内部间隔,例如,边框和内容之间的空格,例如文字或者图片 tooltipShadowColor String #cccccc 使用指定的颜色创建阴影. tooltipShadowWidth String 5 使用指定的宽度(距离)创建阴影. tooltipStatic Boolean false 就像基于操作系统的tooltip, tooltip不随着鼠标光标移动而移动. tooltipSticky Boolean false tooltip一直停留在它初始的位置,直到另外一个tooltip被激活,或者用户点击了文档. tooltipStayAppearTime String 0 指定一个tooltip消失的时间间隔(毫秒),即时鼠标还在相关的HTML元素上不懂,设置<=0,就和没有定义一样. tooltipTextAlign String left 调整包括标题和tooltip内容的文字位置.可以是right, left 或 justify tooltipTitle String none 标题 tooltipTitleColor String #ffffff title文字的颜色 tooltipWidth String 300 tooltip的宽度

    通用属性

    属性 Theme 数据类型 描述 cssClass simple String 定义 html class 属性 cssStyle simple String 定义html style 属性 title simple String 定义html title 属性 disabled simple String 定义html disabled 属性 label xhtml String 定义表单元素的label labelPosition xhtml String 定义表单元素的label位置(top/left),缺省为left requiredposition xhtml String 定义required 标识相对label元素的位置 (left/right),缺省是 right name simple String 表单元素的name映射 required xhtml Boolean 在label中添加 * (true增加,否则不增加) tabIndex simple String 定义html tabindex 属性 value simple Object

    定义表单元素的value

     

     

    value/name的关系

    在很多标签里,除了form标签,在 namevalue 属性之间存在一个独特的关系. name 属性用于得到表单元素的名字以及提交时用到.实际上它也是你希望绑定值的表达式.在大多数情况下,它是一个简单的JavaBean属性,例如 "firstName".这会最终调用setFirstName.

     

    类似的,你经常也希望在你的表单元素里显示相同的JavaBean属性的已经存在的数据.现在, value 属性派上了用场. 一个 "%{firstName}"会调用getFirstName来在你的表单里显示它,允许用户编辑这个值并重新提交它.

     

    <s:textfield label="First name" name="firstName" value="%{firstName}"/>

     

    然而,因为 namevalue 的关系经常是可预知的,我们会自动为你处理这些,这样做就可以:

    <s:textfield label="First name" name="firstName"/>

     

    <s:textfield label="用户名" name="userName" value="abasen" tooltip="Enter your Name here"/>

    ID Name 设置

    所有的表单标签自动为你设置一个 ID. 你可以自由地按照你希望的那样覆盖这个值. ID的设置是这样工作的:

    1. 对于form,ID被设定为action的名字.在前一个例子中,ID会设置为"updatePerson".
    2. 对于表单元素,ID为设定为 [form's ID]_[element name]