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.
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.
[size=medium]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
<ul>
<li> name: <span> show name here</span></li>
</ul>
<table>
<tr>
<td> name: <span> show name here</span></td>
</tr>
</table>
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
<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>
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
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/csdnbig/archive/2005/12/28/563885.aspx
分享到:
相关推荐
这是一个开源的java技术,懂php的人知道php生成页面可以通过模版技术来实现,在java的web开发中,jsp,taglib,jstl等等都是动态的页面技术,因此有人就在开源社区写了个javaweb开发的模版工程,从此java web开发...
fastm.jar fastm.jar
CWBBS的模板技术受启发于Fastm及国内外知名的模板系统,着重于CWBBS社区的应用,并且通过plugin的方式,可以对模板进行扩展。模板目前主要应用于CMS和博客的首页。 通用模板通常是将模板文件预先解析,并以树的形式...
lightweb-轻量级Web框架一个非常简单,快速的Web框架,具有DispatchServlet,Action接口和Config Reading部分。 映射一个网址->一个动作实例。 lightweb非常适用于模板技术,例如Velocity,fastm。
基于Springboot的实验报告系统源码数据库文档.zip
GEE训练教程——Landsat5、8和Sentinel-2、DEM和各2哦想指数下载
基于springboot智能健康饮食系统源码数据库文档.zip
基于SpringBoot的校园服务系统源码数据库文档.zip
内容概要: IXIA测试仪的基本配置.doc ixia测试仪基础使用示例.doc IxNetwork如何进行抓包回放-V1.0.pdf IxNetwork如何自定义报文-V2.0.pdf ixia构造ip分片方法.txt IxNetwork使用简介.pdf 适用人群:网络协议造包、打流相关的测试工程技术人员,想要学习的同学可以下载哈 使用场景:构造pcap包,打流 Ixia简介 IXIA使用的是Server-client模式,Server端在测试仪表的主机上,在开机后会随着主机内的操作系统的启动而自动启动,一般情况下不需要人为的手工启动。因此在通常不需要为主机配置专用的显示器和键盘。 client端包括两个测试软件: Ixia Explorer和ScriptMate。这两个软件一般安装在测试用计算机上,在仪表自带的主机中也有这两个软件。根据测试项目的不同来选择使用不同的软件。Ixia Explorer主要提供数据流的测试,针对设备的功能进行测试; ScriptMate提供各种性能测试窗口,针对设备的性能进行测试。 Auto:自动分配;
基于Python+Django花卉商城系统源码数据库文档.zip
Umi-OCR-main.zip
基于微信小程序开发的促销抽奖小工具源码,适用于初学者了解小程序开发过程以及简单抽奖工具的实现。
GEE训练教程——Landsat5、8和Sentinel-2、DEM和各2哦想指数下载
以下是一个关于Spring Boot设计的资源描述及项目源码的简要概述: Spring Boot设计资源描述 Spring Boot是一个为基于Spring的应用提供快速开发工具的框架,其设计旨在简化Spring应用的初始搭建和开发过程。以下是一些关键资源: Spring Boot官方文档:详细阐述了Spring Boot的核心特性、自动配置原理、起步依赖、内嵌式服务器等关键概念。这是学习和掌握Spring Boot设计的首选资源。 在线教程与视频:各大在线教育平台提供了丰富的Spring Boot教程和视频课程,从基础入门到高级应用,帮助开发者全面了解和掌握Spring Boot设计。 书籍与电子资料:许多技术书籍和在线电子资料深入讲解了Spring Boot的设计原理、最佳实践和项目案例,为开发者提供了宝贵的学习资源。 项目源码示例 以下是一个简单的Spring Boot项目源码示例,用于演示Spring Boot的基本结构和自动配置功能: java // 引入Spring Boot依赖 @SpringBootApplication public class MySpri
基于springboot美妆领域管理系统源码数据库文档.zip
tables-3.7.0+gpl-cp37-cp37m-win_amd64.whl
算法是计算机科学的核心,它们在解决各种问题时发挥着关键作用。一个好的算法不仅可以提高程序的效率,还可以简化复杂的问题。下面我将通过一个具体的例子——快速排序算法(Quick Sort)——来展示算法的实现过程,包括资源描述和项目源码。 ### 快速排序算法简介 快速排序是一种高效的排序算法,采用分治法的思想。其基本步骤如下: 1. 从数列中挑出一个元素,称为“基准”(pivot)。 2. 重新排序数列,所有比基准值小的元素放到基准前面,所有比基准值大的元素放到基准后面(相同的数可以到任一边)。在这个分割结束之后,该基准就处于数列的中间位置。这个称为分割(partition)操作。 3. 递归地(recursive)把小于基准值的子数列和大于基准值的子数列排序。 ### 资源描述 快速排序算法因其高效性和简洁性,在实际应用中非常受欢迎。它的时间复杂度平均为 O(n log n),最坏情况下为 O(n^2),但这种情况很少发生。快速排序的空间复杂度为 O(log n),因为它使用了递归来实现。 快速排序的一个典型应用场景是在数据库系统中对大量数据进行排序。由于它的高效性,快速排序
基于springboot农场投入品运营线上管理系统源码数据库文档.zip
基于springboot个性化影院推荐系统源码数据库文档.zip
linux基础进阶笔记,配套视频:https://www.bilibili.com/list/474327672?sid=4493093&spm_id_from=333.999.0.0&desc=1