Re: Data model traverse
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Friday, March 27, 2009, 5:44:46 PM, wkbutler wrote:
>
> 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)
Now that's magical, in a bad way. What does ${.version} print? Because
it seems I will have to find out what Envionment$1 is... (Currently
it's a TemplateDirectiveBody, and I could achieve this error message
with a trick, but the stack trace doesn't suggest that the error was
achieved with my trick...) Can you access any data-model variables at
all in this template? I guess you can't.
> 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.
And while you are that... exactly which Hibernate version is this?
> I haven't figured out yet how the data model name gets set - what
> should I look for?
Nothing, the data-model has no name, as it's the top-level container
itself. The .data_model thing should just work, but something is
seriously screwed here...
>
>
>
> 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
>>
>>
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------