论坛首页 Java企业应用论坛

对Tapestry的一点思考。

浏览 4096 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-12-27  
Tapestry5已经开发了蛮久了。 听说最近要发布T5.0.7了, 会加上Ajax的功能。 我觉得Tapestry5丢掉了Tapestry的一个非常重要的优点和特色, 那就是把jwcid换成了用xml namespace定义组件了。 这样的话跟jsp里使用tag没什么区别。 很多人当初使用tapestry也是冲着Tapestry能够非常好的预览html, 不会像jsp那样, tag把html页面弄得支离破碎。 这样能够拉近程序员和美工之间的距离,提高工作效率。 如果tapestry还是使用这种方式。 我觉得struts2是更好的选择。

最近也是因为我帮组公司中的其他项目修改页面有感而发的。 那个项目使用seam, 在调整jsf中的dateTable组件时非常不爽。

感觉Tapestry可能马上会没落下去。 T5搞了这么久都还没有release。 所以也有了一点小的想法。 能不能对T4进行改造, 用spring替换hivemind, 把page class可以向T5那样用个pojo。提高T4的效率。 其实直接点的话就是把T5的page template的写法换回成T4的方式。 使用jwcid。

   发表时间:2007-12-28  
T5完全可以用T4的方式,不过将jwcid改为了t:type来申明类型,两种方式是可选的。
例如:
<html t:type="layout/default" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<form t:type="form" t:id="userForm">
      <table>
        <tr>
          <td colspan="2">
            <t:errors />
          </td>
        </tr>
        <tr>
          <td>
            <label for="name" t:type="label" accesskey="F">姓名:</label>

            <span class="required">*</span>
          </td>

          <td>
            <input type="text" t:id="name" t:type="TextField" value="user.name"  t:validate="required,maxlength=10" />
          </td>
        </tr>

        <tr>
          <td>
            <label for="password" t:type="label" accesskey="E">密码:</label>

            <span class="required">*</span>
          </td>

          <td>
<input type="hidden" t:id="password" t:type="PasswordField" value="user.password"   t:validate="required,maxlength=10" />
          </td>
        </tr>
           <tr>
          <td>
            <label for="sex" t:type="label" accesskey="E">性别:</label>

            <span class="required">*</span>
          </td>

          <td>
<input type="select" t:id="sex" t:type="Select" value="user.sex"   model="sexSelectModel"/>
          </td>
        </tr>

        <tr>
          <td>
          </td>

          <td id="submit">
            <input type="submit" value="Submit" class="submit" />

            <input type="reset" value="Reset" class="submit" />
          </td>
        </tr>
      </table>
    </form>
</html>

官方上的介绍
Invisible Instrumentation

A favorite feature of Tapestry 4 is invisible instrumentation, the ability to mark ordinary HTML elements as components. Invisible instrumentation leads to more concise templates that are also more readable.

For Tapestry 5, you make use of namespaced id or type attributes to mark an arbitrary element as a component, for example:

<p>
    Merry Christmas:
    <span t:type="Count" end="3">
        Ho!
    </span>
</p>

The id, type and mixins attributes must be placed in the Tapestry namespace. Any additional attributes may be in the Tapestry namespace or in the default namespace. Placing an attribute in the Tapestry namespace is useful when the attribute is not defined for the element being instrumented.

A component must have a type, either via the t:type attribute in the template, or by the defining the component in the Java class using the Component annotation (and using the t:id attribute on the element in the template).

In most cases,it is an aesthetic choice between normal emebedded components, and embedded components via invisible instrumentation. In a few instances, such as the Loop component, the behavior of the component is influenced by your choice. The Loop component, when included using invisible instrumentation, will render the tag and any informal parameters, around its body. Thus, for example:

  <table>
    <tr t:type="loop" source="items" value="item" class="prop:rowClass">
      <td>${item.id}</td>
      <td>${item.name}</td>
      <td>${item.quantity}</td>
    </tr>
  </tabel>

Here, the loop component "merges into" the <tr> element. It will render out a <tr> for each item object in the items list. It will write a dynamic class attribute into each <tr>.
0 请登录后投票
   发表时间:2007-12-28  
不好意思 昨天晚上头脑发热了。 以前搞过一个项目,是用的input type="select" t:id="sex" t:type="Select"  这种写法的。   好久没用T5了。
0 请登录后投票
   发表时间:2007-12-31  
不可否认的是,Tapestry5实在让人等的花儿都谢了
Java WebFramework在web2.0这一波的确有点落伍。
几乎没有新创,一方面Java崇尚ROR(Tapestry),一方面向.net靠拢(Seam).却一直作为不多

0 请登录后投票
   发表时间:2008-01-02  
喜欢T4,不喜欢T5,也是感觉它越来越回去了。
这次升级变动太大,不喜欢这种风格。
0 请登录后投票
   发表时间:2008-02-01  
问题在于,T5还使用了新的扩展名tml,而不是原来的html.
0 请登录后投票
   发表时间:2008-02-01  
准备投入到jboss seam中了。  虽然不喜欢JSF。 但是有工具的支持还是比较喜人。现在正在读Java Server Faces: The Complete Reference. 感觉还可以。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics