Re: why this doesn't work ? please help.

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
It's maybe because the Field *class* is not public.

-- 
Best regards,
 Daniel Dekany


Tuesday, March 2, 2010, 6:12:29 AM, czy11421 wrote:

> Hi, ALL,
>
> I try to use Freemarker to do a code generation. I am a new to this. 
> Here is the coding, but it doesn't work, it complains
>
> freemarker.core.InvalidReferenceException: Expression fld.name is 
> undefined on line 3, column 19 in src/example.ftl.
>
> Could you please tell me the reason ?
>
> Here is the java code and template file.
>
> Thanks.
> Edward
>
>
>
> ////////////// code //////////
> package com;
>
> import java.io.OutputStreamWriter;
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.Map;
>
> import freemarker.template.Configuration;
> import freemarker.template.Template;
>
> public class Test {
>
>     public static void main(String[] args) {
>
>         try {
>             Configuration cfg = new Configuration();
>
>             Map datamodel = new HashMap();
>             datamodel.put("CName", "Employee");       
>             datamodel.put("fldList", getFld());
>
>             Template tpl = cfg.getTemplate("./src/example.ftl");
>
>             OutputStreamWriter output = new OutputStreamWriter(System.out);
>             tpl.process(datamodel, output);
>
>         } catch (Exception e) {
>             e.printStackTrace();
>
>         }
>
>     }
>    
>     public static ArrayList<Field> getFld() {
>         ArrayList<Field> list = new ArrayList<Field>();
>         list.add(new Field("String", "name"));   
>         return list;
>     }
>
> }
>
> class Field {
>     public String name;
>     public String type;
>    
>     public Field(){    }
>    
>     public Field(String type, String name){
>         this.type = type;
>         this.name = name;           
>     }
>    
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public String getType() {
>         return type;
>     }
>
>     public void setType(String type) {
>         this.type = type;
>     }
>
>     @Override
>     public String toString() {       
>         return this.name+"--"+this.type;
>     }
>
>
> }
>
> ////////////////// FTL template ////////////
> public class ${CName}{
>     <#list fldList as fld>
>         ${fld.name}       
>     </#list>    
> }
>
>
>
>
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>



------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
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.