2

I configured my web application like this link http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch17s04.html

My context

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/freemarker/" />
    <property name="freemarkerSettings">
        <props>
            <prop key="tag_syntax">square_bracket</prop>
            <prop key="auto_import">spring.ftl as spring, echannels.ftl as echannels
            </prop>
            <prop key="template_update_delay">2147483647</prop>
        </props>
    </property>
</bean>

<bean id="htmlViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <property name="contentType" value="text/html;charset=ISO-8859-1" />
    <property name="cache" value="${viewResolver.html.cache}" />
    <property name="prefix" value="html/" />
    <property name="suffix" value=".html" />
</bean>

I use spring-webflow to link all my page html. In my page html, i can access to conversion scope variables by using ${name_variable}. My question is: how could i access to FreeMarker variable "foo" in my html if i defined it in my context:

<bean id="freemarkerConfig"
    class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/freemarker/" />
    <property name="freemarkerVariables">
        <map>
            <entry key="foo" value="foo" />
        </map>
    </property>
</bean>

Example of my HTML

<html>
<head>
    <title>Welcome</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>

<body>
    <h1>Welcome ${issuerId}</h1>

    <form action="?execution=${flowExecutionKey}" method="post" name="defineFeeForm">
        <input type="submit" name="_eventId_next" value="Next" /> <br/>
    </form>
</body>

I can access to ${issuerId} because i have request.setConversationScope("issuerId", "1234") but i want to access also to foo freemarker variable but when i use ${foo}, i got Expression foo is undefined. Any ideas?

khong07
  • 316
  • 1
  • 4
  • 10
  • I don't know Spring MVC so I just comment... According the Spring JavaDoc `freemarkerVariables` calls set `freemarker.template.Configuration.setAllSharedVariables`. If that's true, `foo` should be visible simply as ${foo}. So either your view doesn't use that freemarker.Configuration object that you think it does, or you happen to have another `foo` variable in the data-model (or in even higher layers) that's null. – ddekany Aug 19 '11 at 11:31

1 Answers1

2

Thanks to @ddekany , it's worked, there're nothing wrong in my configuration. I confused before. :). Yes, foo is visible simply as ${foo}.

Another remark, if i want to add new variables during running of my application, i can use

Map<String, Object> variables = new HashMap<String, Object>();
variables.put("foo2", "foo2");
freeMarkerConfigurer.getConfiguration().setAllSharedVariables(new SimpleHash(variables,  freeMarkerConfigurer.getConfiguration().getObjectWrapper()));

and i can access with ${foo2}.

Thanks again. It's done now.

khong07
  • 316
  • 1
  • 4
  • 10