struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ken Hoying (JIRA)" <j...@apache.org>
Subject [jira] Created: (WW-3386) JavaTemplateEngine in mixed theme application
Date Wed, 17 Feb 2010 18:06:28 GMT
JavaTemplateEngine in mixed theme application
---------------------------------------------

                 Key: WW-3386
                 URL: https://issues.apache.org/jira/browse/WW-3386
             Project: Struts 2
          Issue Type: Bug
          Components: Other
    Affects Versions: 2.1.8.1
            Reporter: Ken Hoying


The JavaTemplateEngine Plugin does not work if you have mixed tags in your application.  For
example, if your application utilizes ajax tags as well as simple tags then you will get an
error like this:

{code}
Cannot render tag [head] because theme [ajax] was not found. - [unknown location]
        at org.apache.struts2.views.java.JavaTemplateEngine.renderTemplate(JavaTemplateEngine.java:58)
        at org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:559)
        at org.apache.struts2.components.UIBean.end(UIBean.java:513)
{code}

I had attempted to fix the issue by overriding the TemplateEngineManager by adding the bean
to my struts.xml file.  However, Struts would not allow me to override this and gave me the
exception:

{code}
Caused by: Unable to load bean: type:org.apache.struts2.components.template.TemplateEngineManager
class:com.premierinc.sca.actions.util.ScaTemplateEngineManager - bean - vfsfile:/C:/jboss5/server/sca-app/deploy/scaEar.ear/webapp.war/WEB-INF/classes/struts.xml:40:71
        at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:221)
        at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
        at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:169)
        at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
{code}

Unfortunately, there also does not appear to be a good way to alter the configuration of these
elements.  I was eventually able to do this.  I created a copy of the struts-default.xml and
placed it in my class path with a different name.  In this new default xml I replaced the
configuration for the TemplateEngineManager with one that specified my class.  I then updated
the filter configuration in my web.xml to load my default xml file instead of the struts default
xml.

{code:xml}
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
		</filter-class>
		
		<!-- Override so that we can replace struts-default.xml with struts-sca-default.xml -->
		<init-param>
        	<param-name>config </param-name>
        	<param-value>struts-sca-default.xml,struts-plugin.xml,struts.xml</param-value>
        </init-param>
	</filter>
{code}

In my custom TemplateEngineManager, I extended the existing TemplateEngineManager and overrode
the getTemplateEngine() as such:

{code:java}
    public TemplateEngine getTemplateEngine(Template template, String templateTypeOverride)
    {
        TemplateEngine engSelected = super.getTemplateEngine(template, templateTypeOverride);
        
        if(engSelected instanceof JavaTemplateEngine)
        {
            if("simple".equalsIgnoreCase(template.getTheme()))
            {     
                return engSelected;
            } // end if
            else
            {
                // JavaTemplateEngine currently only supports the "simple" theme, so need
to override
                return super.getTemplateEngine(template, DEFAULT_TEMPLATE_TYPE);
            } // end else
        } // end if
        else
        {
            return engSelected;
        } // end else        
    } // end getTemplateEngine
{code}

However, it seems like the JavaTemplateEngine Plugin should work and play better with the
ajax theme out of the box.

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


Mime
View raw message