advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Reviews : FreeMarker: Separating the Model and Presentation Layers :

System Flow/Architecture

FreeMarker's strength is derived in separating the model layer from the presentation layer. FreeMarker does this by having a data model to represent the model layer and a template to represent the presentation layer. Marrying the data model and the template produces the desired result. The result could be Java classes, HTML, XML, plain text, RTF, or any output. This paradigm makes it easier to separate the business logic from the presentation cleanly and gives developers and designers the independence they crave. Normally, developers can't start working on the user interface until the designers are done with the look and feel. Then, developers are forced to wade through tons of HTML tags, stylesheets, and DHTML code to insert the business logic to make the page dynamic. Once the business logic is embedded, the desired look and feel is often not achieved due to misaligned CSS tags or incomplete HTML elements. Designers then have to make modifications again to regain the look and feel. This reworking process costs time, money, and makes code maintenance a nightmare. Just imagine having to make modifications to the page!

FreeMarker allows programmers and developers to work independently on the model layer and the view layer without stepping on each other’s toes. A designer can start working on the presentation layer with just the outline of a data model. The designer creates the presentation layer in their tool of choice and references elements in the data model using a simple scripting language. Meanwhile, developers can independently work on the model layer and populate the data model with the actual values that need to be inserted into the presentation layer.

The Data Model

The data model is a collection of data arranged in a tree format. At the very beginning is the root element and from it sprouts the different branches of data. Branches have logical groups of data that are specific to a view. They can be independent or shared, depending on the requirements of the presentation layer. The data in a branch can be anything from simple data types like integer, string, or Boolean to complex data types like maps, lists, and Java beans. FreeMarker converts the DataModel to objects of the type freemarker.template.TemplateModel. It uses an ObjectWrapper (freemarker.template.ObjectWrapper) to wrap the Java type in an appropriate TemplateModel. For instance, strings are wrapped as SimpleScalar, a Java object of type Number maybe wrapped by SimpleNumber and so on. Java Beans and other objects are wrapped using freemarker.ext.beans.BeansWrapper. The wrapping of Java beans is done through Java reflection.

Templates

A template is a file that contains static text interpolated with special FreeMarker tags in them. The tags give the dynamic quality to the template and can be used to insert data dynamically from the model. As discussed earlier, FreeMarker tags are written in the FreeMarker Template Language (FTL). They are straightforward and can be used by any designer with a little experience with scripting languages.

FreeMarker Template Language (FTL):

Interpolation is the process by which part of a string, which is marked with special tags, is processed and substituted with processed output before the whole string is printed to the target output stream. Here's the syntax for string interpolation:
 ${ variable_name }
Everything that needs interpolation must be within the ${ and } tags. The variable_name should be an element from the DataModel.

FTL Directives enable users to process and format data just like you would in a regular programming language. Some of the built-in directives provided by FreeMarker are loop constructs, inclusion of external data, decision points etc.

FTL Directives are similar to HTML tags, in that:

  • They must be in angular brackets <>, with the difference being that the first character after the start angular bracket must be the #. For instance, <#list>.
  • Every tag has a start and end tag. The end tag should be the same as the starting tag.
  • Every tag must be properly nested.
FTL Expressions are a combination of variables from the DataModel, arithmetic operators, logical operators, interpolations, etc. FTL Expressions are used to gather and process data from different elements before they are evaluated. This allows for scripting language-like flexibility within the presentation layer.

After the template has been loaded, it is parsed, merged with the DataModel, and then printed to the desired output stream. Once a template has been parsed, it is cached and subsequent requests for the same template results in the same instance being returned. This results in optimal use of memory and enhances execution speed.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Avaya DevConnect Center
 Service Component Architecture/Service Data Objects Solution Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 53
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Cisco Romancing Linux Developers
MobiUI Snares ActionEngine in iPhone/Mobile Push
Windows 7: It's Not Just a Codename Anymore
Microsoft Shines Silverlight on Eclipse
OpenOffice Hits 3.0: Can It Challenge Microsoft?
Get Ready for Microsoft's 'Oslo' Modeling Tool
Latest Linux Hits Networking Flaws
Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next

Intel Sees Fewer Power Cords in Your Future
F# 101
Use Explicit Conversion Functions to Avert Reckless Implicit Conversions
Polyglot Programming: Building Solutions by Composing Languages
Automated testing for .NET by Ben Hall
"Supply Chain" SOA with SKOS
Service Component Architecture in Real Life
C++Ox: The Dawning of a New Standard
Getting Started with Virtualization
Master Complex Builds with MSBuild

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: BitLocker Encryption on Windows Server 2008
Go Parallel Article: Intel Thread Checker, Meet 20 Million LOC
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Amyuni Download: PDF & XPS Engine for Your .NET and ActiveX Applications
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES