Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use the <a href="http://freemarker.org/docs/api/freemarker/template/utility/ObjectConstructor.html" rel="nofollow">ObjectConstructor</a> API of Freemarker to create a calendar object and a formatter object, then combine the two to print the date:</p> <pre><code>&lt;#-- Create constructor object --&gt; &lt;#assign objectConstructor = "freemarker.template.utility.ObjectConstructor"?new()&gt; &lt;#-- Call calendar constructor --&gt; &lt;#assign clock = objectConstructor("java.util.GregorianCalendar")&gt; &lt;#-- Call formatter constructor --&gt; &lt;#assign mmddyy = objectConstructor("java.text.SimpleDateFormat","MM/dd/yyyy")&gt; &lt;#-- Call getTime method to return the date in milliseconds--&gt; &lt;#assign date = clock.getTime()&gt; &lt;#-- Call format method to pretty print the date --&gt; &lt;#assign now = mmddyy.format(date)&gt; &lt;#-- Display date --&gt; ${now} </code></pre> <blockquote> <p>The <code>?new</code> built-in, as it was implemented, was a security hole. Now, it only allows you to instantiate a java object that implements the <code>freemarker.template.TemplateModel</code> interface. If you want the functionality of the ?new built-in as it existed in prior versions, make available an instance of the <code>freemarker.template.utility.ObjectConstructor</code> class to your template. For example: </p> </blockquote> <pre><code>myDataModel.put("objConstructor", new ObjectConstructor()); </code></pre> <blockquote> <p>and then in the template you can do this: </p> </blockquote> <pre><code>&lt;#assign aList = objConstructor("java.util.ArrayList", 100)&gt;) </code></pre> <p><strong>References</strong></p> <ul> <li><p><a href="http://freemarker.org/docs/versions_2_3.html" rel="nofollow">Freemarker 2.3: Version History</a></p></li> <li><p><a href="http://struts.apache.org/docs/freemarker.html" rel="nofollow">Tag Developers Guide: Freemarker</a></p></li> <li><p><a href="http://www.programming-free.com/2013/07/crud-operations-using-servlet-and.html" rel="nofollow">CRUD Operations using Servlet and FreeMarker Template Engine</a></p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload