简体   繁体   中英

freemarker configuration in struts2

I am using freemarker 2.3.21 with struts 2.3.24, I need to configure (customize) freemarker for the struts.

Why ?

Because in FTL file I need to change the default number formatting to " computer" format

Problem

Numbers are printing with default formatting, for example, 12345 will print in FTL file as 12,345 so this number becomes a string when I need to re-use it.

Basic Solution I set the number formatting in the java program and test the solution that is working properly and this solution will work for that ftl which are processed with below object.

Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
        cfg.setClassForTemplateLoading(FTLUtility.class, ftlRootUrl);
        cfg.setNumberFormat("computer"); // this will show the number without formatting 

But in case of struts, it's using other configuration which I don't know where that configuration exists. I need to customize that one.

I know that we can use ${someNumverVar?c} that will resolve my problem but I don't want to replace each variable like this.

if you have any idea or suggestion please feel free to share with me.

According to the Struts documentation, you can specify the FreeMarker configuration settings with the freemarker.properties file, which should be "in the classpath". (The list of the settings can be found in the FreeMarker API docs of Configuration.setSetting )

BTW, don't use 2.3.21; that's a very old version. (I don't mean the incompatibleImprovements , but the version of the jar.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM