5/02/2010

Tapestry Zone

Tapestry Zone 定義一個可動態被更新區域,在頁面中利用Ajax或者其它Client side effect來驅動它。

雖然大家都會寫ajax了,但是很少人去定義被更新區域叫Zone,真的是滿有意義定義及規範。 在Tapestry Zone可以讓開發者簡易且有規範輕鬆做出動態更新功能,我們並不需要太專注於javascript撰寫!

如何做? 

demo.tml,定義counterZone將會有actionlink來驅動顯示它

[html]

You have clicked the link ${clickCount} times.

increment the count

[/html]

demo.java page,對於Tapestry而言Zone被視為Component,使用InjectComponent Annotation注入

[java] public class Demo { @Property @Persist private int clickCount; @InjectComponent private Zone counterZone; Object onActionFromClicker() { clickCount++; return counterZone.getBody(); } } [/java]

Tapestry Zone封裝了ajax 實作和縮減不必要開發成本,大大提升開發效率。最後,Zone當然還有很多變形用法如配合MultiZoneUpdate多區域更新,ProgressiveDisplay用來實作progressive enhancement web design strategy都是不錯的想法。

No comments:

Post a Comment