Re: call java methods

Denis Bredelet <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>

> Hi all,
> You can call java method by using the following points :-
> 1) Create new class the implements TemplateMethodModel interface
> package com.araqa;
> import java.util.List;
> import freemarker.template.SimpleNumber;
> import freemarker.template.TemplateMethodModel;
> import freemarker.template.TemplateModelException;
> 
> public class FreeMarkerMethod implements TemplateMethodModel{
>       @Override
>       public Object exec(List arg0) throws TemplateModelException {
>            return new SimpleNumber(System.currentTimeMillis());
>       }
> }
> 2) write the below command in the Freemaker template to call the exec(..)
> method.
> <#assign utility = "com.araqa.FreeMarkerMethod"?new() > 
> ${utility("x")}
> 

I would not recommend using new() in the template. Just add utility to the model:

datamodel.put("utility", new FreeMarkerMethod());

-- Denis. 
> 
> Best Regards,
> Ahmad Alhaj Hussine
> 
> --
> View this message in context: http://freemarker.624813.n4.nabble.com/call-java-methods-tp625908p3821825.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
> 
> ------------------------------------------------------------------------------
> BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
> http://p.sf.net/sfu/rim-devcon-copy2
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.