Tapestry5学习小结之二(Loop&ActionLink的基本应用)

Start.html
  1. <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">      
  2. <head>      
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>      
  4. <title>${message:page-title}</title>     
  5. <body>   
  6. <p>      
  7. <t:Loop source="prop:1..10" value="prop:index">      
  8.     <a t:type="ActionLink" t:id="select" t:context="prop:index">${index}a> --      
  9. </t:Loop>   
  10. <p>      
  11. <t:If test="selected">      
  12. you selected: <strong>${selected}</strong>      
  13. </t:If>   
  14. </p>   
  15. </body>   
  16. </html>   

Start.properties:
文本 代码
 
  1. page-title=中文标题  

Start.java
java 代码
 
  1. package org.examples.pages;  
  2.   
  3. //import org.apache.tapestry.annotations.OnEvent;  
  4. import org.apache.tapestry.annotations.Persist;  
  5.   
  6. public class Start {  
  7.          
  8.     private int _index;  
  9.       
  10.     @Persist  
  11.     private int _selected;  
  12.       
  13.     public int getIndex(){  
  14.         return _index;  
  15.     }  
  16.     public void setIndex(int index){  
  17.         _index = index;  
  18.     }  
  19.     public int getSelected(){  
  20.         return _selected;  
  21.     }  
  22.     public void setSelected(int selected){  
  23.         _selected = selected;  
  24.     }  
  25.       
  26.     //@OnEvent(component="select")  
  27.     void onActionFromSelect(int index){  
  28.         _selected = index;  
  29.     }  
  30. }  


小结:
1.用Start.properties来显示非英文字符,在HTML模板中使用表达式${message:*}, *是在properties中定义。
2.Action的事件驱动有二种方式:一是使用annotation @OnEvent(component="select"),然后任意定义一个方法名,如上可以为:void chose(int index);二是按照默认规则定义方法名,以on+动作名称+From+组件ID名,如上动作为Action,组件ID为select(<t:comp id="select" context="prop:index" type="ActionLink">中的id),则方法名为:onActionFromSelect(int index)。
3.Action是默认的事件类型,如果页面中有其他事件类型,则需要声明value值,如:@OnEvent(value="action",component="select")
4.Loop组件包含了之前Count组件,现在核心组件中已无Count组件。</t:comp>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值