spring - Unable to use macros with velocity in email templates? -


greetings using velocity templates when sending emails , want read texts dynamically property files depending on user locale

the xml config:

<bean id="messagesource" class="org.springframework.context.support.reloadableresourcebundlemessagesource">       <property name="basenames">      <list>      <value>classpath:messages</value>      <value>classpath:messages_ar</value>      </list>      </property>      <property name="defaultencoding" value="utf-8"/> </bean>  <bean id="velocityengine"         class="org.springframework.ui.velocity.velocityenginefactorybean">         <property name="velocityproperties">             <props>             <prop key="resource.loader">class</prop>             <prop key="class.resource.loader.class">org.apache.velocity.runtime.resource.loader.classpathresourceloader</prop>             <prop key="velocimacro.library">org/springframework/web/servlet/view/velocity/spring.vm</prop>             </props>         </property>     </bean> 
<bean id="velocityconfig" class="org.springframework.web.servlet.view.velocity.velocityconfigurer"> <property name="resourceloaderpath" value="/web-inf/classes/com/spacerdv/mailtemplates"/> </bean>       <!--     view resolvers can configured resourcebundles or xml files. if need   different view resolving based on locale, have use resource bundle resolver.     -->  <bean id="viewresolver" class="org.springframework.web.servlet.view.velocity.velocityviewresolver">   <property name="cache" value="true"/>   <property name="prefix" value=""/>   <property name="suffix" value=".vm"/>   <!-- if want use spring velocity macros, set property true -->   <property name="exposespringmacrohelpers" value="true"/> </bean> 

and when trying read text property file :

<span>#springmessage("hi.message")</span> 

it doesn't read thing, or prints default value, prints:

$springmacrorequestcontext.getmessage($code) 

i don't know why? , missing ?, ?

when using velocity engine sending emails, may have configure engine tu use velocimacro librabry shipped within spring.

<bean id="velocityengine" class="org.springframework.ui.velocity.velocityenginefactorybean">   <property name="velocityproperties">     <props>       <prop key="resource.loader">class</prop>         <prop key="class.resource.loader.class">org.apache.velocity.runtime.resource.loader.classpathresourceloader</prop>         <prop key="velocimacro.library">org/springframework/web/servlet/view/velocity/spring.vm</prop>     </props>   </property> </bean> 

you can check the example in spring documentation.

if spring doesn't inject automatically $springmacrorequestcontext variable model, should put yourself:

model.put("springmacrorequestcontext", new requestcontext(request, response, getservletcontext(), model)); 

that's in abstracttemplateview class. guess won't able it, since you're handling emails here, , not web requests. that's hint on can working.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -