Revolutionary template tech-fastm

Source: Internet
Author: User
Tags xsl
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 abve 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 shocould 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:

 

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 shoshould 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 des source, sample, Doc of faw.1.0m, and view adapter for springmvc, webwork.

Https://fastm.dev.java.net/servlets/ProjectDocumentList? Folderid = 1552 & expandfolder = 1552 & folderid = 0

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.