yientau
Apr 22nd, 2007, 11:07 AM
How shall I "include" the decorator to a page ? it will be best describe in scenario.
I have have the following files and contents
/WEB-INF/web.xml
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.Freema rkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>ISO-8859-1</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
/WEB-INF/decorators.xml
<decorators defaultdir="/decorators">
<decorator name="default" page="default.ftl">
<pattern>/*</pattern>
</decorator>
<decorator name="panel" page="panel.ftl"/>
</decorators>
/decorators/default.ftl
<html>
<head>
<title>Testing</title>
${head}
</head>
<body>
${body}
</body>
</html>
/decorators/panel.ftl
<body>
Testing from panel
${body}
</body>
/WEB-INF/pages/main.ftl
<#assign page=JspTaglibs["http://www.opensymphony.com/sitemesh/page"]>
<head>
<title>Panel testing</title>
</head>
<@page.applyDecorator name="panel"/>
<body>
Test from Main
</body>
It throws me ERROR when I run the main.ftl page. It throws the following errors :-
java.lang.NullPointerException: ServletConfig cannot be null com.opensymphony.module.sitemesh.Config.<init>(Config.java:29)
com.opensymphony.module.sitemesh.taglib.page.Apply DecoratorTag.doStartTag (ApplyDecoratorTag.java:128)
freemarker.ext.jsp.TagTransformModel$TagWriter.onS tart (TagTransformModel.java:243)
freemarker.core.Environment.visit(Environment.java :205)
freemarker.core.UnifiedCall.accept(UnifiedCall.jav a:116)
freemarker.core.Environment.visit(Environment.java :171)
freemarker.core.MixedContent.accept(MixedContent.j ava:92)
freemarker.core.Environment.visit(Environment.java :171)
freemarker.core.Environment.process(Environment.ja va:156)
freemarker.template.Template.process(Template.java :219)
org.springframework.web.servlet.view.freemarker.Fr eeMarkerView.processTemplate(FreeMarkerView.java:3 33)
org.springframework.web.servlet.view.freemarker.Fr eeMarkerView.doRender (FreeMarkerView.java:269)
org.springframework.web.servlet.view.freemarker.Fr eeMarkerView.renderMerged TemplateModel(FreeMarkerView.java:214)
org.springframework.web.servlet.view.AbstractTempl ateView.renderMergedOutpu tModel(AbstractTemplateView.java:178)
org.springframework.web.servlet.view.AbstractView. render (AbstractView.java:247)
org.springframework.web.servlet.DispatcherServlet. render (DispatcherServlet.java:1103)
org.springframework.web.servlet.DispatcherServlet. doDispatch (DispatcherServlet.java:840)
org.springframework.web.servlet.DispatcherServlet. doService (DispatcherServlet.java:754)
org.springframework.web.servlet.FrameworkServlet.p rocessRequest (FrameworkServlet.java:399)
org.springframework.web.servlet.FrameworkServlet.d oGet (FrameworkServlet.java:354)
javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
com.opensymphony.module.sitemesh.filter.PageFilter .parsePage (PageFilter.java:119)
com.opensymphony.module.sitemesh.filter.PageFilter .doFilter (PageFilter.java:55)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:264)
org.acegisecurity.intercept.web.FilterSecurityInte rceptor.invoke (FilterSecurityInterceptor.java:107)
org.acegisecurity.intercept.web.FilterSecurityInte rceptor.doFilter (FilterSecurityInterceptor.java:72)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.ui.ExceptionTranslationFilter.do Filter (ExceptionTranslationFilter.java:110)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.providers.anonymous.AnonymousPro cessingFilter.doFilter (AnonymousProcessingFilter.java:125)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.ui.rememberme.RememberMeProcessi ngFilter.doFilter (RememberMeProcessingFilter.java:135)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.wrapper.SecurityContextHolderAwa reRequestFilter.doFilter (SecurityContextHolderAwareRequestFilter.java:81)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.ui.AbstractProcessingFilter.doFi lter (AbstractProcessingFilter.java:217)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274) org.acegisecurity.ui.logout.LogoutFilter.doFilter( LogoutFilter.java:108)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.context.HttpSessionContextIntegr ationFilter.doFilter (HttpSessionContextIntegrationFilter.java:193)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274) org.acegisecurity.util.FilterChainProxy.doFilter (FilterChainProxy.java:148) org.acegisecurity.util.FilterToBeanProxy.doFilter (FilterToBeanProxy.java:98)
Anyone knows what's the reason of throwing that error? or am I calling the wrong decorator ? My main problem now is I can't access to decorator "panel" from my main.ftl.
Note also that my decorators path(/decorators) and my template path(/WEB-INF/pages) are different. Is this a bug or I am missing out some steps ? Any other references(sites) that I can refer ? Thanks in advance.
I have have the following files and contents
/WEB-INF/web.xml
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.Freema rkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>ISO-8859-1</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
/WEB-INF/decorators.xml
<decorators defaultdir="/decorators">
<decorator name="default" page="default.ftl">
<pattern>/*</pattern>
</decorator>
<decorator name="panel" page="panel.ftl"/>
</decorators>
/decorators/default.ftl
<html>
<head>
<title>Testing</title>
${head}
</head>
<body>
${body}
</body>
</html>
/decorators/panel.ftl
<body>
Testing from panel
${body}
</body>
/WEB-INF/pages/main.ftl
<#assign page=JspTaglibs["http://www.opensymphony.com/sitemesh/page"]>
<head>
<title>Panel testing</title>
</head>
<@page.applyDecorator name="panel"/>
<body>
Test from Main
</body>
It throws me ERROR when I run the main.ftl page. It throws the following errors :-
java.lang.NullPointerException: ServletConfig cannot be null com.opensymphony.module.sitemesh.Config.<init>(Config.java:29)
com.opensymphony.module.sitemesh.taglib.page.Apply DecoratorTag.doStartTag (ApplyDecoratorTag.java:128)
freemarker.ext.jsp.TagTransformModel$TagWriter.onS tart (TagTransformModel.java:243)
freemarker.core.Environment.visit(Environment.java :205)
freemarker.core.UnifiedCall.accept(UnifiedCall.jav a:116)
freemarker.core.Environment.visit(Environment.java :171)
freemarker.core.MixedContent.accept(MixedContent.j ava:92)
freemarker.core.Environment.visit(Environment.java :171)
freemarker.core.Environment.process(Environment.ja va:156)
freemarker.template.Template.process(Template.java :219)
org.springframework.web.servlet.view.freemarker.Fr eeMarkerView.processTemplate(FreeMarkerView.java:3 33)
org.springframework.web.servlet.view.freemarker.Fr eeMarkerView.doRender (FreeMarkerView.java:269)
org.springframework.web.servlet.view.freemarker.Fr eeMarkerView.renderMerged TemplateModel(FreeMarkerView.java:214)
org.springframework.web.servlet.view.AbstractTempl ateView.renderMergedOutpu tModel(AbstractTemplateView.java:178)
org.springframework.web.servlet.view.AbstractView. render (AbstractView.java:247)
org.springframework.web.servlet.DispatcherServlet. render (DispatcherServlet.java:1103)
org.springframework.web.servlet.DispatcherServlet. doDispatch (DispatcherServlet.java:840)
org.springframework.web.servlet.DispatcherServlet. doService (DispatcherServlet.java:754)
org.springframework.web.servlet.FrameworkServlet.p rocessRequest (FrameworkServlet.java:399)
org.springframework.web.servlet.FrameworkServlet.d oGet (FrameworkServlet.java:354)
javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
com.opensymphony.module.sitemesh.filter.PageFilter .parsePage (PageFilter.java:119)
com.opensymphony.module.sitemesh.filter.PageFilter .doFilter (PageFilter.java:55)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:264)
org.acegisecurity.intercept.web.FilterSecurityInte rceptor.invoke (FilterSecurityInterceptor.java:107)
org.acegisecurity.intercept.web.FilterSecurityInte rceptor.doFilter (FilterSecurityInterceptor.java:72)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.ui.ExceptionTranslationFilter.do Filter (ExceptionTranslationFilter.java:110)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.providers.anonymous.AnonymousPro cessingFilter.doFilter (AnonymousProcessingFilter.java:125)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.ui.rememberme.RememberMeProcessi ngFilter.doFilter (RememberMeProcessingFilter.java:135)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.wrapper.SecurityContextHolderAwa reRequestFilter.doFilter (SecurityContextHolderAwareRequestFilter.java:81)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.ui.AbstractProcessingFilter.doFi lter (AbstractProcessingFilter.java:217)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274) org.acegisecurity.ui.logout.LogoutFilter.doFilter( LogoutFilter.java:108)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274)
org.acegisecurity.context.HttpSessionContextIntegr ationFilter.doFilter (HttpSessionContextIntegrationFilter.java:193)
org.acegisecurity.util.FilterChainProxy$VirtualFil terChain.doFilter (FilterChainProxy.java:274) org.acegisecurity.util.FilterChainProxy.doFilter (FilterChainProxy.java:148) org.acegisecurity.util.FilterToBeanProxy.doFilter (FilterToBeanProxy.java:98)
Anyone knows what's the reason of throwing that error? or am I calling the wrong decorator ? My main problem now is I can't access to decorator "panel" from my main.ftl.
Note also that my decorators path(/decorators) and my template path(/WEB-INF/pages) are different. Is this a bug or I am missing out some steps ? Any other references(sites) that I can refer ? Thanks in advance.