You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Daniel Dekany (JIRA)" <ji...@apache.org> on 2018/01/18 10:11:01 UTC

[jira] [Comment Edited] (FREEMARKER-87) <#list map as key,value> should always iterating on map entries

    [ https://issues.apache.org/jira/browse/FREEMARKER-87?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16330335#comment-16330335 ] 

Daniel Dekany edited comment on FREEMARKER-87 at 1/18/18 10:10 AM:
-------------------------------------------------------------------

The template language constructs (such as the {{#list}} directive) don't look inside {{TemplateModel}}-s, that is, they don't want to know what have you wrapped into the model. They only depend on the {{TemplateModel}} interfaces. That's also why something that's not a {{Map}}, like a usual JavaBean or a DOM {{Node}} can be treated similarly as a {{Map}} in templates, despite that the template language constructs aren't aware of those concepts (JavaBeans, {{Node}}-s, etc.).

So, if you don't want to expose the methods like map entries, then don't use such a model, like {{MapModel}}. {{DefaultObjectWrapper}} (which is what FreeMarker uses by default) doesn't do that. Using pure {{BeansWrapper}} is not recommended, but if you have to use that, then you can still set its {{simpleMapWrapper}} property to {{true}} to avoid exposing methods like that. But again, it's recommended to use {{DefaultObjectWrapper}} (with {{incompatibleImprovements}} set to some high value, like 2.3.27 as of this writing). However, I'm not sure what's compatible with Strut's FreeMarker libraries.

That the behavior of {{MapModel}} is still isn't practical... yeah. Just don't use it. It can't be fixed, as that breaks backward compatibility.


was (Author: ddekany):
The template language constructs (such as the {{#list}} directive) don't look inside {{TemplateModel}}-s, that is, they don't want to know what have you wrapped into the model. They only depend on the {{TemplateModel}} interfaces. That's also why something that's not a {{Map}}, like a usual JavaBean or a DOM {{Node}} can be treated similarly as a {{Map}} in templates, despite that the template language constructs aren't aware of those concepts (JavaBeans, {{Node}}-s, etc.).

So, if you don't want to expose the methods like map entries, then don't use such a model, like {{MapModel}}. {{DefaultObjectWrapper}} (which is what FreeMarker uses by default) doesn't do that. Using pure {{BeansWrapper }}is not recommended, but if you have to use that, then you can still set its {{simpleMapWrapper}} property to {{true}} to avoid exposing methods like that. But again, it's recommended to use {{DefaultObjectWrapper}} (with {{incompatibleImprovements}} set to some high value, like 2.3.27 as of this writing). However, I'm not sure what's compatible with Strut's FreeMarker libraries.

That the behavior of {{MapModel}} is still isn't practical... yeah. Just don't use it. It can't be fixed, as that breaks backward compatibility.

> <#list map as key,value> should always iterating on map entries
> ---------------------------------------------------------------
>
>                 Key: FREEMARKER-87
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-87
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.27-incubating
>            Reporter: Yanming Zhou
>            Priority: Major
>         Attachments: MapIteratingTest.java
>
>
> I'm using struts2, use FriendlyMapModel instead of default MapModel, It works fine except map have key such as "size", the value will be unexpected SimpleMethodModel, I think freemarker should always use entry value for directive <#list map as key,value>, not matter how MapModel works, MapModel should only affect map.size and map.get('size').
> I attached a test case.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)