Vikings

TapeStry 4.0 beta 新特性 1-3

[原文]
http://spaces.msn.com/members/jface/PersonalSpace.aspx?_c01_blogpart=blogmgmt&_c=blogpart

Tapestry4新特性(一)-default binding types

一、default binding types(默认的绑定类型)
    每一个组件的参数都可以定义默认的绑定类型,如果一个绑定的参数没有前缀,将使用默认的绑定类型。
    下面的代码实现同样的功能:

   

     加粗的部分显示前后的变化,之所以可以这样定义,是因为Insert组件定义value参数的默认绑定类型为ongl.
     注意:默认的绑定参数总是可以被显式的绑定声明覆盖掉。
    如果没有定义默认的绑定参数,那么在html模板中定义的默认绑定参数为literal,页面定义文件里的默认绑定参数为ognl

修订:

从beta4版本开始,此特性已经被删除,

Beta4的change log:

 Remove default-binding attribute from element(HLS)

但是“如果没有定义默认的绑定参数,那么在html模板中定义的默认绑定参数为literal,页面定义文件里的默认绑定参数为ognl”这个效果经测试依然存在。

怀念:

此段文字在beta3中存在,beta4后就删掉了!

Binding Type Defaults

Tapestry 4.0 introduces a new idea: default binding types. Each component parameter may define a default binding type (using the default-binding attribute of the element).

If a binding reference does not have a prefix, the default binding type is used.

Because of this, the following two snippets are identical:

This works because the Insert component defines the default-binding for the value parameter to be "ognl". Likewise, the source and value parameters of the Foreach component are defined to be "ognl". However, the element parameter of the Foreach component has a binding type of "literal".

This is a decision made by the component author. If a particular parameter is (nearly) always bound using a particular binding type, then a default-binding may be set. The default binding can always be overriden with an explicit binding type prefix.

What about parameters that don't define a default binding type? The answer to this question (which includes all informal parameters), is that it depends on whether the parameter is bound in an HTML template, or in a page or component specification. In an HTML template, the default binding type is "literal". In a specification, the default binding type is "ognl".



Tapestry4新特性(二)-listener method
二、listener method
     如果使用过tapestry的应该知道listener方法在4.X以前版本中的定义,如public void formSubmit(IRequestCycle cycle),方法必须
有一个IRequestCycle参数。参数的取得方式如下:Object[] parameters = cycle.getServiceParameters();
     在4.X中参数的取得可以通过以下两种方式:
  1. 调用IRequestCycle.getListenerParameters()方法,需要传入IRequestCycle实例作为参数。
  2. 按照参数的声明顺序依次定义为listener方法的参数。

     第二种方法比较符合软件的设计思维,而且参数的类型在传入后保存,而不是想象中的统一String类型。
例如:
. . .
其中objectId为String类型,index为int,声明中使用了默认的参数绑定类型。
对应的方法声明如下
public void doClick(String objectId, int index)
{ . . . }
此为第二种方式,可见方法的定义符合自然习惯,当然你也可以通过传统的方法,如下所示: public void doClick(IRequestCycle cycle)
{ Object[] parameters = cycle.getListenerParameters();
String objectId = (String)parameters[0];
int index = ((Integer)parameters[1]).intValue(); . . . } 
这种方式是为了向后兼容以前的版本,当然也适用那种参数数目不确定的情况。 Tapestry默认搜索以下的方法声明:

  • public void method(parameters)(页面的跳转 cycle.activate()如何实现?)
  • public void method(IRequestCycle cycle, parameters) (倾向于使用此方式)
  • public void method()(无需参数传递和页面跳转的情况,估计可能性不大)
  • public void method(IRequestCycle cycle)(传统方式)
   不要试图通过参数的类型来映射listener方法,tapestry是根据参数的数目来确定方法的。

Tapestry4新特性(三)-global property source
三、Global Property Source(全局的消息属性配置)
消息属性配置听起来不是很舒服,暂时这样称呼好了,消息属性配置也就是通称的国际化配
置,通过配置一个properties文件使不同语言的浏览者看到对应语言的版本,一般
的使用如下,一个page页面,例如example.page,同目录下放一个
example.properties,在 example.html中使用来指定显示值,
中文可以使用example_zh_CN.properties来配置。看起来挺方便的,可
tapestry4.0以前的版本的国际化不支持全局的属性配置文件,必须每个页面定义
自己的,无法几个页面共享,但实际开发中,多页面共享属性配置是很常见的,
tapestry4.0中可以通过以下方式获得全局的属性配置文件:
创建一个跟你的项目全局配置文件,如yourApp.application,此文件在4.0以前的
版本中是必须的,4.0中如果没有必要配置,可以不需要此文件(扯远了),yourApp
是根据你在web.xml定义的,例如

tapesty4
org.apache.tapestry.ApplicationServlet
1

那属性定义文件就应该是tapestry4.properties,这样在此文件中定义一个:test=
测试,在Home.html中使用< span key="test">test
,看到“测试”正确显示。

posted on 2005-11-08 17:55 Vikings 阅读(319) 评论(0)  编辑  收藏 所属分类: frame-work


只有注册用户登录后才能发表评论。


网站导航: