I am trying to use Freemarker template. Here is what I do:

public Representation getRepresentation(Variant variant) {

 Representation result = null;

 if (variant.getMediaType().equals(MediaType.TEXT_HTML)) {

   String html = "<h4>PAGE NOT FOUND</h4>";

   Page page = null;

   try {
        // page is just a POJO with 
        //id, title and content properties set elsewhere

    page = populateFromNotes(pageID); 

    if (page != null) {
      html = page.getHtmlPageRepresentation(); }


// <- works

  // result = new StringRepresentation(html, MediaType.TEXT_HTML,
              Language.ENGLISH_US); 

 // <- does not work

  result = new TemplateRepresentation("page.ftl", Naviquan.freeMarkerConfig,
             page, MediaType.TEXT_HTML);

      }

      catch (Exception ex) {

        ex.printStackTrace();

        html = "<h4>ERROR</h4>\n" + ex.toString(); }

    }


    return result;

  }


When I use StringRepresentation everything works as expected. When I switch to
TemplateRepresentation the page is rendered, but the browser keeps loading and
loading. I also noticed that content-length is not set in the header (whereas 
if I use StringRepresentation it's set as well as charset=ISO-8859-1 in content
type):
http://localhost/page/000009B6

GET /page/000009B6 HTTP/1.1

Host: localhost

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.5)
Gecko/20070713 Firefox/2.0.0.5
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;
q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 200 The request has succeeded
Date: Thu, 19 Jul 2007 16:44:36 GMT
Server: Noelios-Restlet-Engine/1.0.2
Content-Type: text/html
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Connection: close


Is my use of TemplateRepresentation correct? 

Thanks,

Serge

Reply via email to