process - Processing struts2 tags in freemarker templates -


i have requirement process freemarker ftl file on server side , return html client. know if possible process freemaker template having struts tags in using template.process().

action class code:

// configuration created struts2 freemarkermanager freemarkermanager freemarkermanager = new freemarkermanager(); configuration config = freemarkermanager.getconfiguration(context);  //configuration without specific settings. configuration config = new configuration(); //tried both nothing works.  template template = config.gettemplate("template path");  map<string, object> inputmap = new hashmap<string, object>(); inputmap.put("document", document);  stringwriter output = new stringwriter(); template.process(inputmap, output); 

freemarker template:

<#assign s=jsptaglibs["/struts-tags"]>     <table>         <tr>            <th><@s.text name="document name"/></th>            <th><@s.text name="description"/></th>         </tr>         <@s.iterator value="inspiration" status="status">     <tr>     <td class="nowrap"><@s.property value="properties.document_name"/></td>     <td class="nowrap"><@s.property value="properties.description"/></td>     </tr>         </@s.iterator>     </table> 

i have added struts-tags.tld under web-inf folder.

exception

freemarker.core.invalidreferenceexception: expression jsptaglibs undefined on line 1,

if remove <#assign s=jsptaglibs["/struts-tags"]>

freemarker.core.invalidreferenceexception: expression s undefined on line 7

define custom transform method, such following:

 public static void process( servletcontext context, string template, map values, writer writer) throws ioexception, templateexception  {  configuration cfg = new configuration();  cfg.setdirectoryfortemplateloading(new  file(context.getrealpath("/templates")));  cfg.setobjectwrapper(new defaultobjectwrapper());   beanswrapper wrapper = beanswrapper.getdefaultinstance();   templatehashmodel staticmodels = wrapper.getstaticmodels();   template temp = cfg.gettemplate(template);   temp.process(values, writer);   writer.flush();  } 

references


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -