Struts 2
  1. Struts 2
  2. WW-3764

Reading(theme.properties)PropertyFileFromFileSystem doesn't include templatePath value from web.xml

    Details

    • Flags:
      Important

      Description

      There is an option in Struts2 to load the freemarker template from path by setting in web.xml (templatePath).Templates are loaded from the file system if we configure the file path.

      Also there is an option to extend the themes by setting the value for "parent" key in the themes.properties within the template folder

      readProperty() method helps us to read the themes.properties file from the file system and also from the classpath
      Aruguments :-
      Combination of template directory ,template and file name "theme.properties" are passed as propName

      This method doesn't help us to load the theme.properties from the specified templatePath

      private InputStream readProperty(String propName) {
      InputStream is = tryReadingPropertyFileFromFileSystem(propName);
      if (is == null)

      { is = readPropertyFromClasspath(propName); }

      return is;
      }

        Issue Links

          Activity

          Vijayakannan created issue -
          Hide
          Lukasz Lenart added a comment -

          Did you try to configure struts.ui.templateDir ?

          Show
          Lukasz Lenart added a comment - Did you try to configure struts.ui.templateDir ?
          Hide
          Lukasz Lenart added a comment -

          theme.properties are loaded from struts.ui.templateDir if specified. Or do I miss something ?

          Show
          Lukasz Lenart added a comment - theme.properties are loaded from struts.ui.templateDir if specified. Or do I miss something ?
          Hide
          Vijayakannan added a comment -

          When i try to load the struts default template from application path "/WEB-INF/template" by setting struts.ui.templateDir in stuts.xml, i am geting this Exception.

          SEVERE: Could not open template
          java.io.FileNotFoundException: Template /WEB-INF/template/xhtml/a.ftl not found.
          at freemarker.template.Configuration.getTemplate(Configuration.java:489)
          at freemarker.template.Configuration.getTemplate(Configuration.java:452)
          at org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:96)
          at org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:559)
          at org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java:59)
          at org.apache.struts2.components.Anchor.start(Anchor.java:132)
          at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)

          Show
          Vijayakannan added a comment - When i try to load the struts default template from application path "/WEB-INF/template" by setting struts.ui.templateDir in stuts.xml, i am geting this Exception. SEVERE: Could not open template java.io.FileNotFoundException: Template /WEB-INF/template/xhtml/a.ftl not found. at freemarker.template.Configuration.getTemplate(Configuration.java:489) at freemarker.template.Configuration.getTemplate(Configuration.java:452) at org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:96) at org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:559) at org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java:59) at org.apache.struts2.components.Anchor.start(Anchor.java:132) at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
          Hide
          Vijayakannan added a comment -

          Root cause for the above Exception:

          FreemarkerTemplateEngine.java :- List<Template> templates = templateContext.getTemplate().getPossibleTemplates(this);

          The above method call BaseTemplateEngine.java loadProperties(String propName) method to load the theme.properties for the template.

          This method internally calls readProperty(String propName)method to load the properties file from file system /class path but not from application path.

          private Properties loadProperties(String propName) {
          InputStream is = readProperty(propName);
          Properties props = new Properties();
          if (is != null)

          { tryToLoadPropertiesFromStream(props, propName, is); }

          return props;
          }

          private InputStream readProperty(String propName) {
          InputStream is = tryReadingPropertyFileFromFileSystem(propName);
          if (is == null)

          { is = readPropertyFromClasspath(propName); }

          return is;
          }

          Value of propName in my case ="WEB-INF/template/xhtml/theme.properties"

          Please create unit test case for the loadProperties("WEB-INF/template/xhtml/theme.properties") method to understand the problem more details.

          Show
          Vijayakannan added a comment - Root cause for the above Exception: FreemarkerTemplateEngine.java :- List<Template> templates = templateContext.getTemplate().getPossibleTemplates(this); The above method call BaseTemplateEngine.java loadProperties(String propName) method to load the theme.properties for the template. This method internally calls readProperty(String propName)method to load the properties file from file system /class path but not from application path. private Properties loadProperties(String propName) { InputStream is = readProperty(propName); Properties props = new Properties(); if (is != null) { tryToLoadPropertiesFromStream(props, propName, is); } return props; } private InputStream readProperty(String propName) { InputStream is = tryReadingPropertyFileFromFileSystem(propName); if (is == null) { is = readPropertyFromClasspath(propName); } return is; } Value of propName in my case ="WEB-INF/template/xhtml/theme.properties" Please create unit test case for the loadProperties("WEB-INF/template/xhtml/theme.properties") method to understand the problem more details.
          Lukasz Lenart made changes -
          Field Original Value New Value
          Fix Version/s 2.3.x [ 12319176 ]
          Fix Version/s 2.5.x [ 12319198 ]
          Hide
          Vijayakannan added a comment -

          Hope you have understand the above mentioned issue.

          Issue # 2 in the ticket

          struts.xml
          <constant name="struts.ui.templateDir" value="struts-template"></constant>

          web.xml

          <context-param>
          <param-name>TemplatePath</param-name>
          <param-value>file://D://templates</param-value>
          </context-param>

          The purpose of TemplatePath is more powerful when compare to others, since it helps us to load the template from file system.

          when i try to load the template from file system, i am getting FileNotException.

          java.io.FileNotFoundException: Template /struts-template/xhtml/a.ftl not found.
          at freemarker.template.Configuration.getTemplate(Configuration.java:489)
          at freemarker.template.Configuration.getTemplate(Configuration.java:452)
          at org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:96)

          Root Cause:

          BaseTemplateEngine.java loadProperties(String propName) method doesn't include TemplatePath which is defined in web.xml.

          private InputStream readProperty(String propName) {
          InputStream is = tryReadingPropertyFileFromFileSystem(propName);
          if (is == null)

          { is = readPropertyFromClasspath(propName); }

          return is;
          }

          In my case , propName is "struts-template/xhtml/theme.properties"

          Please note i have raise two related problem in this ticket.

          Thanks in advance

          Show
          Vijayakannan added a comment - Hope you have understand the above mentioned issue. Issue # 2 in the ticket struts.xml <constant name="struts.ui.templateDir" value="struts-template"></constant> web.xml <context-param> <param-name>TemplatePath</param-name> <param-value> file://D://templates </param-value> </context-param> The purpose of TemplatePath is more powerful when compare to others, since it helps us to load the template from file system. when i try to load the template from file system, i am getting FileNotException. java.io.FileNotFoundException: Template /struts-template/xhtml/a.ftl not found. at freemarker.template.Configuration.getTemplate(Configuration.java:489) at freemarker.template.Configuration.getTemplate(Configuration.java:452) at org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:96) Root Cause: BaseTemplateEngine.java loadProperties(String propName) method doesn't include TemplatePath which is defined in web.xml. private InputStream readProperty(String propName) { InputStream is = tryReadingPropertyFileFromFileSystem(propName); if (is == null) { is = readPropertyFromClasspath(propName); } return is; } In my case , propName is "struts-template/xhtml/theme.properties" Please note i have raise two related problem in this ticket. Thanks in advance
          Lukasz Lenart made changes -
          Assignee Lukasz Lenart [ lukaszlenart ]
          Hide
          Vijayakannan added a comment -

          Lukasz Lenart Any updates ?

          Show
          Vijayakannan added a comment - Lukasz Lenart Any updates ?
          Lukasz Lenart made changes -
          Fix Version/s 2.3.4 [ 12320768 ]
          Fix Version/s 2.3.x [ 12319176 ]
          Vijayakannan made changes -
          Issue Type Temp [ 12 ] Improvement [ 4 ]
          Hide
          Lukasz Lenart added a comment -

          No, I'll postpone it till 2.3.5

          Show
          Lukasz Lenart added a comment - No, I'll postpone it till 2.3.5
          Lukasz Lenart made changes -
          Fix Version/s 2.3.5 [ 12321274 ]
          Fix Version/s 2.3.4 [ 12320768 ]
          Hide
          Lukasz Lenart added a comment -

          Could you prepare a small example application as I cannot grasp where the problem is :/

          Show
          Lukasz Lenart added a comment - Could you prepare a small example application as I cannot grasp where the problem is :/
          Lukasz Lenart made changes -
          Fix Version/s 2.3.6 [ 12323249 ]
          Fix Version/s 2.3.5 [ 12321274 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.7 [ 12323448 ]
          Fix Version/s 2.3.6 [ 12323249 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.8 [ 12323480 ]
          Fix Version/s 2.3.7 [ 12323448 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.9 [ 12323841 ]
          Fix Version/s 2.3.8 [ 12323480 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.10 [ 12323903 ]
          Fix Version/s 2.3.9 [ 12323841 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.12 [ 12324067 ]
          Fix Version/s 2.3.11 [ 12323903 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.13 [ 12324132 ]
          Fix Version/s 2.3.12 [ 12324067 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.14 [ 12324256 ]
          Fix Version/s 2.3.13 [ 12324132 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.15 [ 12324267 ]
          Fix Version/s 2.3.14 [ 12324256 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.16 [ 12324546 ]
          Fix Version/s 2.3.15 [ 12324267 ]
          Lukasz Lenart made changes -
          Link This issue is related to WW-4145 [ WW-4145 ]
          Hide
          Lukasz Lenart added a comment -

          When WW-4145 will be solved we can start working on this

          Show
          Lukasz Lenart added a comment - When WW-4145 will be solved we can start working on this
          Lukasz Lenart made changes -
          Fix Version/s 2.3.17 [ 12324780 ]
          Fix Version/s 2.3.16 [ 12324546 ]
          Lukasz Lenart made changes -
          Fix Version/s 2.3.x [ 12319176 ]
          Fix Version/s 2.3.17 [ 12324780 ]

            People

            • Assignee:
              Lukasz Lenart
              Reporter:
              Vijayakannan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development