[ 
https://issues.apache.org/jira/browse/TOMAHAWK-1319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12625827#action_12625827
 ] 

Leonardo Uribe commented on TOMAHAWK-1319:
------------------------------------------

Checking this code

public void encodeTemplate(FacesContext context, UIComponent component, 
Renderer renderer, String template, Object dataModel) throws IOException {
        if(log.isDebugEnabled())
            log.debug("Encoding template : " + 
renderer.getClass().getResource(TEMPLATE_DIRECTORY+"/"+template));
        Configuration cfg = getConfig(context, TEMPLATE_CACHE);
        DefaultTemplateLoader templateLoader = 
(DefaultTemplateLoader)cfg.getTemplateLoader();
        templateLoader.setLoaderClass(renderer.getClass(), TEMPLATE_DIRECTORY);
        Template temp = cfg.getTemplate(template);
        try
        {
            temp.process(dataModel, context.getResponseWriter());
        }
        catch (TemplateException e)
        {
            throw new IOException(e.getMessage());
        }
    }

The method 

        templateLoader.setLoaderClass(renderer.getClass(), TEMPLATE_DIRECTORY);

is awful when concurrency cases occurs. I don't believe that a custom template 
class loader is the right solution (as is provided on the patch), rather use 
the original, but only use absolute template class loading!.


> DefaultTemplateEncoder does not cache FreeMarker templates
> ----------------------------------------------------------
>
>                 Key: TOMAHAWK-1319
>                 URL: https://issues.apache.org/jira/browse/TOMAHAWK-1319
>             Project: MyFaces Tomahawk
>          Issue Type: Bug
>          Components: Template Renderer
>    Affects Versions: 1.1.7-SNAPSHOT
>         Environment: tomcat 6.0.16
> java 1.6.0_05
> MyFaces tomahawk-sandbox-1.1.7-SNAPSHOT
>            Reporter: Paul Rivera
>            Priority: Minor
>         Attachments: DefautlTemplateEncoder-Caching.patch
>
>
> The DefaultTemplateEncoder used by TemplateRenderer does not cache the 
> templates properly.
> In DefaultTemplateEncoder.encodeTemplate(), it instantiates a new 
> Configuration instance every time this method is called.  FreeMarker's cache 
> is stored in Configuration->TemplateCache->CacheStorage.  If we keep creating 
> a new instance of Configuration in DefaultTemplateEncoder.encodeTemplate(), 
> the CacheStorage will always be empty and FreeMarker will have to parse the 
> file again.
> Here's the code:
> public class DefaultTemplateEncoder implements TemplateEncoder {
>     private static final Log log = 
> LogFactory.getLog(DefaultTemplateEncoder.class);
>     private static final String TEMPLATE_DIRECTORY = "template";
>     public void encodeTemplate(FacesContext context, UIComponent component, 
> Renderer renderer, String template, Object dataModel) throws IOException {
>          Configuration cfg = new Configuration();
>          if(log.isDebugEnabled())
>              log.debug("Encoding template : " 
> +renderer.getClass().getResource(TEMPLATE_DIRECTORY+"/"+template));
>          TemplateLoader templateLoader = new 
> ClassTemplateLoader(renderer.getClass(), TEMPLATE_DIRECTORY);
>    ...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to