[ 
https://issues.apache.org/jira/browse/WW-3522?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12924297#action_12924297
 ] 

Li Ying commented on WW-3522:
-----------------------------

I see.

Thanks a lot.

> Template Overriding not work
> ----------------------------
>
>                 Key: WW-3522
>                 URL: https://issues.apache.org/jira/browse/WW-3522
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>         Environment: All
>            Reporter: Li Ying
>         Attachments: WW-3522.patch
>
>   Original Estimate: 5h
>  Remaining Estimate: 5h
>
> ===========================================================
> The problem:
> If you modify some template of Struts2 tag, and put it into a folder under 
> the web root.
> then the new template file should override the old template shipped with 
> Struts2.
> It is described in this document:
> http://struts.apache.org/2.2.1/docs/template-loading.html
> But in Struts2.2.1, it not works. The old template, but not the new template, 
> always get used.
> ===========================================================
> My investigation report:
> I have spent several hours on this problem, and i think i have found what is 
> wrong.
> (1) In class [org.apache.struts2.views.freemarker.FreemarkerManager], there 
> are method [init] and [createTemplateLoader]
> (2) In method [init], it read the servlet context parameter "TemplatePath" or 
> "templatePath", if either of them are set, FreemarkerManager will use
> a default value, which is "class://"
> (3) In method [createTemplateLoader], it will create a ClassTemplateLoader 
> (if the value of "TemplatePath" starts with "class://") or a 
> FileTemplateLoader(if the value of "TemplatePath" starts with "file://"), and 
> this TemplateLoader will get a higher priority than WebappTemplateLoader.
> (4) If you don't set parameter [TemplatePath], the default value "class://" 
> will cause a ClassTemplateLoader be created. And it will always load template 
> from [Struts2-core.2.2.1.jar] successfully, so the WebappTemplateLoader get 
> no chance to load the overridden template files.
> So, if you use the default setting, Template overriding will not work in 
> Struts2.2.1.
> The only way to make it work is:
> set a invalid value for [TemplatePath], then FreemarkerManager will ignore 
> it, and
> don't create ClassTemplateLoader or FileTemplateLoader,
> so WebappTemplateLoader will get work correctly.
> I have looked the SVN, it looks like these codes were changed in revision 
> 835248 at Nov/12/2009.
> The previous revision 719672 use the parameter [TemplatePath] as an absolute 
> file path, and only create the FileTemplateLoader.
> That why there were not this bug in this revision.
> ===========================================================
> My suggestion:
> Delete the default value of [TemplatePath].
> If user don't set it, then neither ClassTemplateLoader nor FileTemplateLoader 
> should be created.
> Only if user set it, they explicitly want it, then ClassTemplateLoader or 
> FileTemplateLoader should be created.

-- 
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