Results 1 to 3 of 3

Thread: Problem in Spring Email + ResourceBundle use in velocity template

  1. #1
    Join Date
    Aug 2009
    Posts
    10

    Default Problem in Spring Email + ResourceBundle use in velocity template

    Hello,

    Hope someone can help me on this.

    I'm using Struts2 + Spring (and Spring Email + Velocity)
    I follow this example http://static.springsource.org/sprin...ence/mail.html
    and I'm trying to make the email template be i18N.

    I'm searching hard in google but only find limited information, here is what I did

    In my spring application.xml

    Code:
    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
    		<property name="velocityProperties">
    			<value>
    				resource.loader=class
    				class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
    			</value>
    		</property>
    </bean> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
            <property name="exposeSpringMacroHelpers"><value>true</value></property>
    </bean> 
    <bean id="messageSource" 
    		class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basenames">
    			<list>
    				<value>resources.global-messages</value>				
    			</list>
    		</property>
    </bean>
    global-message.properties file is put under my WEB-INF/classes/resources directory.

    This is part of the email template

    Code:
    <html>
    <body>
    <h1>#springMessage("label.welcome")</h1>
    I'm not sure this is correct way or not, but it is not getting the message from properties file.

    Could anyone please give me some light on this?

    Thanks
    LV

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    The I18N only works for web pages not email templates.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2009
    Posts
    10

    Thumbs up

    Ok, finally I solve my problem by passing whole resource and local object to velocity.

    In my email service class, I did this:

    Code:
    Map model = new HashMap();
    model.put("user", user);
    model.put("resources",this.resource);
    model.put("locale", this.locale);
    String text = VelocityEngineUtils.mergeTemplateIntoString(
    	               velocityEngine, "email.html", model);
    
    ....
    
    public void setResource(ResourceBundleMessageSource resource){
    		this.resource = resource;
    }

    In the email template :

    Code:
    <html>
    <body>
    <h1>#msg("label.welcome")</h1>
    In macro.vm
    Code:
    #macro(msg $code)
    $resources.getMessage($code,null,$locale)
    #end
    spring config:
    Code:
    <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">velocity/macro.vm</prop>	            
    	        </props>
        </property>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •