You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Dániel Dékány (Jira)" <ji...@apache.org> on 2022/02/17 08:20:01 UTC

[jira] [Commented] (FREEMARKER-178) Using map or filter built-ins looses custom template model

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

Dániel Dékány commented on FREEMARKER-178:
------------------------------------------

Yes, but since the result of {{?filter}} is a new Java object (made by the template engine), what Java API you expect to be available on the result anyway?

> Using map or filter built-ins looses custom template model
> ----------------------------------------------------------
>
>                 Key: FREEMARKER-178
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-178
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.30
>            Reporter: Steven Davelaar
>            Priority: Major
>
> When you are using a custom template sequence model that implements the 
> TemplateModelWithAPISupport interface so you can use the api built-in, you can no longer use the api built-in once you have applied the map or filter function, because the map and filter functions then return a new instance of TemplateModelListSequence, which does not implement the TemplateModelWithAPISupport interface.
> For example, imagine a custom sequence model that supports the toString() method, then the following works fine:
> {noformat}
> ${myList?api.toString()}{noformat}
> However, when I apply a filter, like this:
> {noformat}
> ${myList?filter(i -> i.name == 'foo')?api.toString()}{noformat}
> I get a APINotSupportedTemplateException because the filter has returned a TemplateModelListSequence instance.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)