Data AccessCore JavaApp FrameworksViewTestingBuildingDeploymentDev ToolsSecurityOpinions

Thursday, December 11, 2008

Check for null in FreeMarker 2.4

With the preview of FreeMarker version 2.4 available, a few enhancements to the template language have really improved FreeMarker's appeal.

Providing a check for "null" is one of the largest enhancements that make it easier for developers to transition to FreeMarker from other view technologies. View the (preview announcement).

Previously in 2.3 and below, a "null" value was essentially treated as a missing variable. The missing value operator was the suggested way of testing for null, as the word "null" is not a reserved word in the template language. Here's a look at the 2.3 documentation on treating undefined variables and null values.

FreeMarker 2.3 and Pre - Missing Value Operator
Assume aVariable is null or not defined.

<#if aVariable??>

If you wanted to check if a string was empty or null in FreeMarker, you might have used has_content, one of the "Seldom used and expert built-ins"

Assume aVariable is null or not defined.

<#if aVariable?has_content>


<#if aVariable!?size > 0 or aVariable!?length > 0>

FreeMarker 2.4 Enhancement
2.4 is now null-aware with other template language enhancements, making null a reserved word in 2.4.


  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

    Online Java Training Java Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai

  2. A few enhancements to the template language have really improved FreeMarker's appeal.learn web deisgn

  3. All the blog works are choice. The more I read, the more fall under the spell of them.
    e-commerce website

  4. Together with the surge of changes realized by the happening to new innovation are relating changes in the conventional managing an account framework, especially in the store and withdrawal forms. Beside the utilization of money itself, clients can likewise execute business with the bank through the alleged check liquidating framework. Check Cashing Lemon-Grove

  5. There are a few shrouded costs in a payday credit! Keep in mind, in the event that you can't pay this loan and you happen to lose your activity, the clock does not stop.Payday Loans Chicago

  6. wow this saintly however ,I love your enter plus nice pics might be part personss negative love being defrent mind total poeple ,
    mason soiza

  7. One of those online journals that has left a critical effect on the hearts of the people.

  8. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
    short term loans no credit check where