Revolutionary Template Tech -- fastm

原创 2005年05月30日 17:37:00

Revolutionary Template Tech -- fastm

1. Overview

There are a lot of template techs on the world, like JSP, Taglib, Freemarker, Velocity, XSL, Jivan, XMLC, Tapestry, Wicket, JDynamiTe, etc.

For more info, please visit.

http://java-source.net/open-source/template-engines

 

The reason why I write “yet another template -- fastm” is just that I can not find a good enough one for me to use.

 

The templates fall into 2 categories:

(1) Script with logic (if, else, for); like JSP, Taglib, Freemarker, Velocity, XSL, Tapestry, etc.

(2) Resource without logic; like Jivan, XMLC, Wicket, fastm, etc.

Here I like to review these templates group by group to list their and disadvantages that I am not satisfied.

2. JSP, Taglib

At first, people write HTML in the Servlet code. The code is polluted by the long HTML.

So JSP is made.  Then people write code in the HTML.  The HTML is polluted by code.

So Taglib is made. People write Taglib as code, since Taglib’s XML format seems look better than code in the HTML.

To display the Taglib in HTML Editors like Dreamweaver, Taglib Display Plugin is made. They are complex jobs.

As we can see, the whole thing is becoming more and more complex.

3. Freemarker, Velocity

Freemarker, Velocty are scripts containing logic like if, else, for, set, etc, which may affect the HTML display effect in the HTML browser.

4. Tapestry, Wicket

Tapestry, Wicket uses HTML tag as its logic tag or page component tag.

Tapestry contains logic like if, else, for, etc, while Wicket contains none.

Both Tapestry and Wicket have their own view model like Label, Link, Table, etc.

You have to write code to put your data into these view models.

5. Jivan, XMLC

www.jivan.org

Jivan and XMLC directly manipulate the HTML DOM node. Pure HTML, no any pollution.

You have to write code to put your data into the DOM node.

6. XSL

XSL directly manipulates the HTML DOM node too.

XSL can be seen as a little complex template script containing logic like match, choose, otherwise, etc.

7. JDynamiTe

http://sourceforge.net/projects/jdynamite

JDynamiTe ports PHPBB template to Java.

Like PHPBB template, you have to write code to search the resource block in the template and then use it.

To solve that problem, I wrote fastm.

8. fastm

Now it is fastm’s turn. Thanks for your patience. :-)

fastm tries to avoid above disadvantages and leverage their advantages.

fastm template is like PHPBB or JDynamiTe template, which uses XML comment as block mark and not contains any logic at all.

 

The formula of fastm is very simple and straight-forward:

Template DOM + Object DOM = Result HTML

 

For example, we have a list of User objects, which has name, address such properties.

We can display the users by following template

 

<!-- BEGIN DYNAMIC: users -->

Name: {name}

Address: {address}

<!-- END DYNAMIC: users -->

 

As we can see, XML Comment not affects HTML display effect in the Browser or HTML Editor like Dreamweaver.

 

For a if-else logic, like

<% if(name == null ){ %>

        No User Name Defined

<%}else if(isSuperUser(name)){%>

        Super User: <%= name %>

<%} else{%>

        Common User : <%= name %>

<%}%>

 

Fastm template should be:

 

<!-- BEGIN DYNAMIC: no_name -->

        No User Name Defined

<!-- END DYNAMIC: no_name -->

 

<!-- BEGIN DYNAMIC: super_user -->

        Super User: {name}

<!-- END DYNAMIC: super_user -->

 

<!-- BEGIN DYNAMIC: common_user -->

        Common User: {name}

<!-- END DYNAMIC: common_user -->

 

The logic is to be moved back to java code as:

 

Map map = new HashMap();

map.put(“name”, name);

If(name == null){
    map.put(“no_name”, map);

} else if(isSuperUser(name)){

    map.put(“super_user”, map);

}else{

    map.put(“common_user”, map);

}

 

Right. fastm template not supports script logic.

You have to write your logic in java code, like Jivan, XMLC, Wicket, etc.

 

As we can see, fastm is very easy and simple to use. And fastm has the fastest speed and smallest size among all template techs. 

 

9. The Good of Driving the Logic back to Java Code

(1) It solves the HTML code pollution. Template can be correctly displayed in the Browsers or HTML Editors.

(2) The logic in the Java code is easy to debug.

(3) The logic in the Java code is easy to reuse.

 

Here is the rationale of fastm:

Business logic is logic. Presentation logic is logic too.

Presentation logic should be organized neatly as Business logic too.

10. Designer friendly

fastm is quite “Designer friendly”.

fastm HTML template can be displayed correctly in the Browers or HTML editors. What you see is what you get”.

Microsoft provides XML formats of office documents.

For example, Excel (2002 or above) file can be saved and edited as XML format.

fastm works quite well for that too.

Fastm Excel XML template can be displayed correctly in the Excel too. “What you see is what you get”.

So in such kinds of “visual XML UI editors”, fastm has more advantages than scripts like JSP, Taglib, XSL, freemarker, velocity, Tapestry.

Wicket has the same “Designer friendly” effect as fastm too.

The most “Designer friendly” templates are Jivan, XMLC. They are just pure HTML, XML.

11. DOM Granularity, Reusability

Compared with XML DOM node, fastm Template DOM node is more flexible, since it is customized by user self.

For example, we want to display a list of users in two kinds of layout: list or table.

 

(1) XML DOM way

[code]

<ul>

<li> name: <span> show name here</span></li>

</ul>

 

<table>

<tr>

<td> name: <span> show name here</span></td>

</tr>

</table>

[/code]

 

As we can see, the 2 DOM level are different.

“List” has 3 levels; “Table” has 4 levels.

 

You may need to write 2 sets of “DOM manipulation” code for the 2 DOMs.

The DOM can not be shared. You modified the DOM, and then output it.

Next time, you need to operation on a fresh-new DOM.

 

(2) fastm way

[code]

<ul>

<!-- BEGIN DYNAMIC: user -->

<li> name: {name}</li>

<!-- END DYNAMIC: user -->

</ul>

 

<table>

<!-- BEGIN DYNAMIC: user -->

<tr>

<td> name: {user}</td>

</tr>

<!-- END DYNAMIC: user -->

</table>

[/code]

 

As we can see, both the “List” and “Table” templates have 2 levels.

We just need one set of code to get same Object DOM for the 2 Template DOMs.

Since the data is organized in the Object DOM, not directly put into the Template DOM, so the Template DOM can be shared. 

fastm Template DOM is read only and thread safe, which can be used any times by any number of concurrent programs.

12. Resource

The old version 1.0 alpha of fastm is on https://sourceforge.net/projects/fastm

The new version 1.0 M of fastm is on https://fastm.dev.java.net/

Please check the “Documents and Files”.

https://fastm.dev.java.net/servlets/ProjectDocumentList

That includes source, sample, doc of fastm1.0M, and view adapter for SpringMVC, WebWork.

https://fastm.dev.java.net/servlets/ProjectDocumentList?folderID=1552&expandFolder=1552&folderID=0

 

设置 VPN (vpn tech runo) FOR UBUNTU

用了yuzhou推荐的vpn ,叫vpn tech runo ,我用的套餐是100/年,目前感觉速度在50kB左右,不能使用P2P,BT否则直接删号,还有,支持支付宝支付 1 VPN TEC...
  • CAZICAQUW
  • CAZICAQUW
  • 2012年05月04日 17:55
  • 8390

Microsoft TechReady-MOSS(Sharepoint)2007深度培训

        11月底MOSS2007即将发布,我现在正在做一期Microsoft TechReady-MOSS(Sharepoint)2007深度培训。为了保证培训的高质量,邀请了Kaneboy、...
  • oceanju
  • oceanju
  • 2006年10月22日 23:52
  • 1398

参加阿里云栖大会Tech Insight,不可错过的6大理由

摘要: 云栖大会北京峰会是Tech Insight继4月深圳云栖大会上的二度亮相,继首次开办总结经验之后,此次议题选择更侧重用户需求,议程设置更为丰满。很多报名的朋友们希望能对日程、讲师以及参会建议能...
  • yunqishequ1
  • yunqishequ1
  • 2016年07月07日 17:50
  • 1741

AIM Tech Round Div 1

AIM Tech Round Div 1 春节过完急急忙忙先来水几道题... A:题意:给定由一个字符串凿出一个图的过程:字符串仅有a,b,c三种字符,造出的图中第i个顶点表示原来的第i个字符,i与j...
  • jzhang1
  • jzhang1
  • 2016年02月10日 18:27
  • 484

告别难记的长域名!我的博客全新短域名上线

翻阅了一下记录,我的第一篇文章是在2013年3月19号写的,如令一晃三年的时光过去了。很庆幸即使在三年后的今天我还能坚持写着博客,并且在短期可预见的时间里,我暂时还没有停更计划,未来会继续坚持给大家带...
  • sinyu890807
  • sinyu890807
  • 2016年03月31日 09:02
  • 21360

穿戴式移动医疗技术在远程医疗中的应用研究进展综述

1 前言 远程医疗泛指采用多种通信技术进行医用电子数据异地传输的系统,其功能涵盖远程医学检测、监护、咨询、急救、保健、诊断、治疗以及远程教育和管理等诸多方面。 近年来,军队远程医疗在远程医疗咨询、...
  • taozi343805436
  • taozi343805436
  • 2013年08月08日 15:07
  • 1735

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)A+B

A. A Serial Killertime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inp...
  • qq_33183401
  • qq_33183401
  • 2017年02月24日 12:51
  • 261

HDU 1015 Safecracker 题解

Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is locked in a Kle...
  • kenden23
  • kenden23
  • 2014年07月10日 15:58
  • 1293

fastm设计思路深度剖析

  • zgqtxwd
  • zgqtxwd
  • 2008年04月25日 05:31
  • 91

Top 6 Ethical Issues in Artificial Intelligence

By Julia Bossmann Optimizing logistics, detecting fraud, composing art, conducting research, pro...
  • joseph2z
  • joseph2z
  • 2017年06月11日 11:57
  • 112
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Revolutionary Template Tech -- fastm
举报原因:
原因补充:

(最多只允许输入30个字)