Re: Data model traverse

wkbutler <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Thanks Daniel.  Maybe data_model has been overridden then, because when I use
your suggestion this is the error I encounter:

Caused by: freemarker.template.TemplateException: Expected extended hash.
.data_model evaluated instead to freemarker.co
re.Environment$1 on line 3, column 10 in appfuse/web/struts/action-test.ftl.
        at
freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:135)
        at
freemarker.core.BuiltIn$keysBI._getAsTemplateModel(BuiltIn.java:594)
        at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
        at freemarker.core.IteratorBlock.accept(IteratorBlock.java:87)
        at freemarker.core.Environment.visit(Environment.java:196)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:196)
        at freemarker.core.Environment.process(Environment.java:176)
        at freemarker.template.Template.process(Template.java:232)
        at
org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:255)


But it's not clear to me in looking at the Template.process() call, if this
is really happening.  

The process(java.lang.Object, java.io.Writer)  method is being given a
freemarker.template.SimpleHash, defined as 
        getContext().put("version", Version.getDefault());
        getContext().put("ctx", getContext());
        getContext().put("templates", new Templates());
        getContext().put("date", new SimpleDate(new Date(), 3));

and I don't see anything else being done at the top level.  I haven't
figured out yet how the data model name gets set - what should I look for? 




Daniel Dekany wrote:
> 
> Wednesday, March 25, 2009, 9:50:38 PM, wkbutler wrote:
>>
>> Hi -
>> I know this has been asked before, but I have not seen an answer that
>> seems
>> to work for me.  I am looking to discover the contents of the data model
>> during template processing time, just for the purpose of setting up a
>> debugging FTL template.
>>
>> Is there a constant keyword for the root of the model?  
>>
>> I have seen .data_model used but for me that was an Environment object
>> (and
> 
> You have overlooked something there; .data_model is the root of the
> data-model itself. It's not an Environment object (of course, unless
> someone uses the Environment object as the data-model parameter in
> Template.process... but that's at best unusual.)
> 
>> accessing .data_model.dataModel as I thought should have been
>> possible, according to the freemarker.core.Environment API, result
>> in an 'undefined' error).
>>
>> This thread asks the same question
>> http://www.nabble.com/traverse-the-data-tree-td6874906.html#a6874906
>>
>> and Attila mentions it's possible but unfortunately did not
>> elaborate. Using <#recurse> is apparently valid but for me resulted
>> in an error also.
> 
> #recurse only works for FTL node values, like wrapped XML-s. I doesn't
> work for plain hashes and like. You should use ?keys on them, like:
> 
> <p>The variables in the data-model are:
> <ul>
>   <#list .data_model?keys as key>
>     <li>${key?html}
>   </#list>
> </ul>
> 
>> Thanks for any advice!
> 
> -- 
> Best regards,
>  Daniel Dekany
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
> 
> 

-- 
View this message in context: http://www.nabble.com/Data-model-traverse-tp22710830p22745176.html
Sent from the freemarker-user mailing list archive at Nabble.com.


------------------------------------------------------------------------------
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.