0

In Spring i need to show message in my ftl file. i am using

<@spring.message "property_name">

and the message comes from my properties file.

i need the mssage like

"Message_content_link"

the test link will be a url which will point to another page. i tried like

properties file

message_content=Message_content
message_link=link

ftl file

<@spring.message "message_content" htmlEscaspe="false"><a href="#url_page"><@spring.message "message_link"></a>
AJJ
  • 3,570
  • 7
  • 43
  • 76
  • This [post](http://stackoverflow.com/questions/17022911/how-to-get-properties-in-jsp-files-using-spring-mvc-3) might help you. – Braj Dec 23 '14 at 15:07
  • This questions could be a duplicate of http://stackoverflow.com/questions/3154804/how-to-use-messages-with-freemarker-in-spring-mvc – David Moreno García Dec 23 '14 at 15:28

1 Answers1

0

FreeMarker now includes the option to expose the Spring Macro Helpers. In your WebMVC config, add resolver.setExposeSpringMacroHelpers(true);

Now in your *.ftl file, you can call springMacroRequestContext.getMessage(code, argsArray, "", escapeHtml)

You can then just assign this to a shorthand function:

<#function msg code args=[] escapeHtml=true>

    <#local argsArray = [] />

    <#if args?is_string>
        <#local argsArray = [args] />
    <#elseif args?is_sequence>
        <#local argsArray = args />
    <#else>
        <#return "" />
    </#if>

    <#return springMacroRequestContext.getMessage(code, argsArray, "", escapeHtml) />

</#function>

See an example here: https://github.com/edendramis/freemarker-example/

ratherblue
  • 2,108
  • 11
  • 14