Browse:

Freemarker Overview

In all templates, m-Power uses the Freemarker template engine to create your Java Servlet Applications. While Freemarker itself is not a "complete" coding language, it is quite powerful and rich with many customizable options.

When you generate any m-Power application, you will see code similar to this in the source of your HTML:

<!-- <#list table_rows as row> -->

<tr> <td nowrap class="${rowClass(row_index)}" align="right">

${row.CUSNO?html}

</td><td nowrap class="${rowClass(row_index)}" align="right">

${row.CMPNO?html}

</td><td nowrap class="${rowClass(row_index)}" align="left">

${row.CNAME?html}

</td> </tr>

<!-- </#list> -->

The first and last lines of the code #list and /#list dictate to your Java Servlet to repeat this section of code for as many records as are requested to be displayed on the screen.

Within m-Power, fields are noted: ${row.CMPNO?html} where CMPNO is the name of your Field. The $ denotes that a Substitution is about to occur. {row. Indicates the location the field is to come from. Alternatives to the {row. Syntax would be row0.FIELDNAME for Single Record Templates, and ${grandTotal, ${subTotal1, ${subTotal2 for Reports. The CMPNO indicates the name of the Field from your Database. Lastly, the ?html indicates the field's encoding.

Note: Any code outside of the <#list> and </#list> tags will only be preformed once.

Basic Coding with Freemarker within Presentation (HTML) Layer

Creating New Variables

Freemarker structure is fully customizable to include some coding placed directly within the presentation (HTML) layer. To assign a variable, use the following syntax:

<!--<#assign variablename=value>-->

Note: For computability reasons within m-Painter, you must wrap all #assign tags within HTML comment tags.

Examples of the #assign tag.

<!--<#assign counter=0>-->

<!--<#assign counter=counter+1>-->

<!--<#assign sometext="Sample Text">-->

To use these variables, simply use the following text: ${counter} where counter is your newly created variable name. Note: There is no "row." logic.

If you wish to create a variable and assign a value from your database, please use the following syntax:

<!--<#assign sometext= row.FIELDNAME>-->Note: Using ${row.FIELDNAME} will cause a Run-Time Error.

If & If/Else Looping

You can also utilize looping within the HTML layer as well. The syntax is as follows:

<!--<#if variable RELATIONSHIP value>-->Note: For computability reasons within m-Painter, you must wrap all #if tags within HTML comment tags.

Code inside If statement

<!--</#if>-->

Valid relationships include all standard relationships, including:

== — Equals

> — Greater than

>= — Greater than or Equal to

< — Less than

< — Less than or Equal to

!= — Not equal to

You can also use Else logic as well:

<!--<#if variable == 0>-->

<!--<#assign variable=7>-->

Variable is equal to 7

<!--<#else>-->Note: For computability reasons within m-Painter, you must wrap all #else tags within HTML comment tags.

Variable is equal to 0

<!--</#if>-->

If you wish to use a Database value within your IF statement, please use the following syntax:

<!--#if sometext== row.FIELDNAME>-->Note: Using ${row.FIELDNAME} will cause a Run-Time Error.

Common Variables

${visitor.user} — Only available when mrc Security has been activated. Will display the User's Sign on name.

${visitor.curDate} — Will return the Date in YYYY-MM-DD format.

${visitor.library} — Will return the name of the Current Data Dictionary.

${visitor.sessionID} — Will return the 32 character Session ID. This ID is unique by Browser Session, thus no two browsers can have the same session ID.

${visitor.remoteIp} — This variable will return the IP address of the Client's browser.

${visitor.loginDate} — This variable will return the Date of the Initial login. It is in the format YYYY-MM-DD. In the absence of mrc Security, it will display the time the application was first accessed.

${visitor.loginTime} — This variable will return the Time of the Initial login. It is in the format HH:MM:SS. In the absence of mrc Security, it will display the time the application was first accessed.

How to Implement your own Freemarker Custom Changes

To make Freemarker changes, compile your application and enter m-Painter. Click the "Source" button and find your <#list> section using m-Painter's Binoculars. It is at this location within the code that you can make all necessary changes.