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

Daniel Dekany commented on FREEMARKER-31:
-----------------------------------------

Because the {{ObjectWrapper}} instance is not bound to the {{Configuration}} 
instance, I don't yet see how to move that setting into the `Configuration`. 
But luckily, you can configure the {{ObjectWrapper}} from the properties file 
too:

{quote}
objectWrapper=DefaultObjectWrapper(2.3.25, 
defaultDateType=freemarker.template.TemplateDateModel.DATE)
{quote}

It's not perfect as then you have specified more things than what you wanted, 
but this is perhaps still an acceptable compromise,

As of making it a top-level setting somehow, right now the only possibility I 
see is to configure FreeMarker to treat {{TemplateDateModel.UNKNOWN}} values as 
the configured date/time type instead of throwing exception. The wrapped 
{{Date}} will still have {{TemplateDateModel.UNKNOWN}} type, but we tolerate 
it. It's not ideal though, as if you pass that date/time value to a 3rd party 
directive for example, which doesn't like {{TemplateDateModel.UNKNOWN}} (nor it 
reads the new {{Configurable}} setting), it will still fail. That's why doing 
it in the {{ObjectWrapper}} is certainly more appropriate.

> Default date type as setting
> ----------------------------
>
>                 Key: FREEMARKER-31
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-31
>             Project: Apache Freemarker
>          Issue Type: Improvement
>          Components: engine
>            Reporter: MichaƂ Sobkiewicz
>
> To set default date type, one have to use 
> {{freemarker.ext.beans.BeansWrapperConfiguration#setDefaultDateType(int)}} or 
> {{freemarker.ext.beans.BeansWrapper#setDefaultDateType(int)}}. It would be 
> convenient to set {{defaultDateType}} by using property.
> {{freemarker.core.Configurable#setSetting(String,String)}} recognises date, 
> time and number formats. It even lets you choose object wrapper! At the same 
> time you can't specify how to deal with not-so-exotic {{java.util.Date}}.
> I'd like to set default date type just as I can set exception handling. I 
> know that {{defaultDateType}} attribute would have to be moved to 
> {{freemarker.template.Configuration}}, but I'm convinced that this is the 
> right thing to do.
> If it makes sense to talk about "default date type" (which seems to be true 
> as {{defaultDateType}} property already exists), it may be also valid to 
> expect a little more accessible way to set this up. With no customized bean 
> wrapper, without adding a bit redundant "?date" after each... well.. date, 
> you end up with 
> {{freemarker.core.UnknownDateTypeFormattingUnsupportedException}}.
> Sample settings below:
> {quote}
> locale=en_US
> dateFormat=yyyy-MM-dd
> numberFormat=0.00
> logTemplateExceptions=false
> templateExceptionHandler=rethrow
> defaultDateType=date
> {quote}
> I truly believe that the last one should be supported.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to