Tapestry 相关的控件介绍

1、Tapestry组件的写法
a、<t:textfield t:id="userName" t:value="jack"/>,这样的写法的优点是,看上去比较直观,与Struts等Web框架的一致。但是缺点就是,使用浏览器(或者美工)直接看页面的时候,浏览器无法正确显示这个组件。
b、<input type="text" t:type="textfield" t:id="userName" t:value="jack"/>这样写的话,浏览器就能正常显示一个文本输入框了。这也是Tapestry一直鼓吹的一大优点之一。
c、在Java类中使用注解来声明组件。这种方法我个人并不推荐,只是一种选择,并不直观也不方便。
d、Tapestry组件标签是不区分大小写的。
2、组件参数的前缀。从官方文档来看,参数的前缀还挺多的:
Prefix        Description
asset        The relative path to an asset file (which must exist).
block        The id of a block within the template.
component        The id of another component within the same template.
context        Context asset: path from context root.
literal        A literal string.
nullfieldstrategy        Used to locate a pre-defined NullFieldStrategy
message        Retrieves a value from the component's message catalog.
prop        A property expression to read or update.
translate        The name of a configured translator.
validate        A validator specification used to create some number of field validators.
var        Allows a render variable of the component to be read or updated.
但最最常用的只有2个:prop和literal
简单的说:prop表示这是一个变量名,literal表明这是一个常量
比如说select这个组件,它的基本写法是: <t:select t:id="color" model="literal:Red,Green,Blue" label="Colour:"/>
查看select的参考文档,model这个参数的缺省前缀是prop,所以如果直接写model="red"的话,Tapestry会认为red是一个变量名,会调用页面对应类的getRed()方法来获得一个列表。所以,此处如果想使用一个常量的话,需要显示指明literal前缀。而label的缺省前缀是literal,所以直接这样写就没有问题。
3、Label,显示一个标签,一般在需要多语言的环境下或者与textField配合使用。
<t:label t:for="userName">Label for the user name</t:label> Lable组件有一个t:for的属性,这个属性的值一般是一个textField的id。我们可以注意到Lable标签里写一段文字,这一段文字在页面部署运行后是不会显示的,写在这里,纯粹是给美工这样的静态页面浏览者看的。在实际运行中这一段文字会被替代。替代的内容就是t:for属性对应的TextField组件的t:id的值,比如:userName。当然Tapestry会自动把userName分成两个单词,而且把user的首字母大写。
如果根据t:id生成的lable不符合要求,可以有另一种选择:直接在textField中指定label:
<input type="text" t:type="textField" t:id="userName" t:label="Input User Name" t:value="jack"/>
4、PageLink,用于显示一个链接,点击后,跳转到指定页面
<a href="#" t:type="pageLink" t:page="register">Register</a>
5、ActionLink,用于显示一个链接,点击后,运行一个可以带有参数的指令。
<a href="#" t:type="actionLink" t:context="id" t:id="clickLink">
        ${user.id}
    </a>
  如果一个参数不够,比如,只用一个id不能唯一确定一个用户,必须结合部门id才能唯一确定用户的话,那么可以这样做:
  <a href="#" t:type="actionLink" t:context="userContext" t:id="clickLink">delete</a>
  相应的在java class中需要添加一个方法:getUserContext()
  public Object[] getUserContext() {
     return new Object[] {user.id, department.id};
  }
6、Loop
Loop并不是一个真正的Form控件,严格说起来是一种逻辑控制语句。语法如下:
<t:loop source="userList" value="user">
    <td>${user.name}</td>
</t:loop>
7、Radio & Radio
            <t:radiogroup t:id="type">
                <t:radio t:id="masterCard"/>
                <t:label for="masterCard"/>
                <t:radio t:id="visa"/>
                <t:label for="visa"/>
                <t:radio t:id="amex"/>
                <t:label for="amex"/>
                <t:radio t:id="dinersClub"/>
                <t:label for="dinersClub"/>
                <t:radio t:id="discover"/>
                <t:label for="discover"/>
            </t:radiogroup>

8、CheckBox
<t:checkbox t:id="showall" οnclick="this.form.submit();"/> <t:label for="showall"/>
9、Select
<t:select t:id="color" model="literal:Red,Green,Blue"/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值