Add RequestContext to Groovy template view model

This commit is contained in:
Dave Syer 2014-05-16 09:41:50 +01:00
parent f572992c5d
commit 7c7d1f55e0
2 changed files with 4 additions and 1 deletions

View File

@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author Dave Syer
* @since 1.1.0
*/
@ConfigurationProperties(prefix = "spring.groovy.template")
@ConfigurationProperties(prefix = "spring.groovy.template", ignoreUnknownFields = false)
public class GroovyTemplateProperties {
public static final String DEFAULT_PREFIX = "classpath:/templates/";

View File

@ -24,6 +24,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.servlet.view.AbstractUrlBasedView;
/**
@ -43,6 +44,8 @@ public class GroovyTemplateView extends AbstractUrlBasedView {
protected void renderMergedOutputModel(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
applyContentType(response);
model.put("spring", new RequestContext(request, response, getServletContext(),
model));
this.template.make(model).writeTo(new BufferedWriter(response.getWriter()));
}