Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've gotten StringTemplate to work with Spring. Basically, all it took was a custom view.</p> <p>But first, a disclaimer: This is an experimental hack. I've never used this in production code, and it could use some improvement before that happens. I think it is adequate to answer your question about how easily StringTemplate integrates with a Web MVC framework, however.</p> <p>Reference: <a href="http://static.springframework.org/spring/docs/2.5.x/reference/mvc.html" rel="noreferrer">Spring Web MVC documentation</a></p> <p>StringTemplateView.java:</p> <pre><code>import java.io.PrintWriter; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.antlr.stringtemplate.StringTemplate; import org.antlr.stringtemplate.StringTemplateGroup; import org.springframework.core.io.Resource; import org.springframework.web.servlet.view.InternalResourceView; public class StringTemplateView extends InternalResourceView { @Override protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Provides a Spring resource descriptor referring to the .st file Resource templateFile = getApplicationContext().getResource(getUrl()); // Kind of redundant... StringTemplateGroup group = new StringTemplateGroup("group", templateFile.getFile().getParent()); StringTemplate template = group.getInstanceOf(getBeanName()); template.setAttributes(model); // Output to client PrintWriter writer = response.getWriter(); writer.print(template); writer.flush(); writer.close(); } } </code></pre> <p>And an example view resolver definition:</p> <pre><code>&lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="viewClass" value="myapp.web.view.StringTemplateView"/&gt; &lt;property name="prefix" value="/WEB-INF/st-views/"/&gt; &lt;property name="suffix" value=".st"/&gt; &lt;/bean&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload