EDIT - All @ characters removed from code snippets to pass new member mention validation *
I’m in need of help with properties set up in a new document type, which isn’t being rendered on my page (FTL template) and giving the “freemarker.core.InvalidReferenceException: The following has evaluated to null or missing” error.
For the purposes of showing the problem, I’ve reduced my FTL template, which was based on the Essentials Carousel template, to just displaying two properties - a title and image. The eventual template and document type will have many more properties, but after running into my issue I removed most to simplify debugging.
My template:
<#include "include/imports.ftl">
<#include "include/setdevglobals.ftl">
<#-- ftlvariable name="componentId" type="java.lang.String" -->
<#-- ftlvariable name="item" type="com.eb.cms.beans.Banner" -->
<#-- ftlvariable name="pageable" type="org.onehippo.cms7.essentials.components.paging.Pageable" -->
<#-- ftlvariable name="cparam" type="org.onehippo.cms7.essentials.components.info.EssentialsCarouselComponentInfo" -->
<#if pageable?? && pageable.items?has_content>
<div class="slide">
<#list pageable.items as item>
<p>>> ${item.title} <<</p>
<#if item.bannerimage??>
<hst.link var="img" hippobean=item.bannerimage />
<#assign cleanimg = img?remove_beginning("/_cmsinternal")>
</#if>
<#if cleanimg?? && cleanimg?has_content>
<p> >> ${cleanimg} <<</p>
</#if>
<#if hstRequest.queryString?? && hstRequest.queryString?contains('carouseldebug=true')>
<#import "include/debugger.ftl" as debugger>
<debugger.debug debugObject=item depth=2 />
</#if>
</#list>
</div>
<#elseif editMode>
<div>
<img src="<hst.link path='/images/essentials/catalog-component-icons/carousel.png'/>"> Click to edit Carousel
</div>
<div class="has-new-content-button">
<hst.manageContent templateQuery="new-banner-document" parameterName="document1" rootPath="banners"/>
</div>
</#if>
My page has a carousel component, which is configured in the console to use the above template.
I created a new document type, with Super type as “basedocument”. The document type has only two properties, a Title (type: String, path: title) and Image (type: Image Link, path: bannerimage). After creating the document type I generated template queries and set up allowed content. I then used the Bean Writer to generate HST Content beans. This is the resulting Java class:
package com.eb.cms.travel.beans;
import org.onehippo.cms7.essentials.dashboard.annotations.HippoEssentialsGenerated;
import org.hippoecm.hst.content.beans.Node;
import com.eb.cms.travel.beans.BannerImageSet;
HippoEssentialsGenerated(internalName = "travelcms2:HomePageBanner")
Node(jcrType = "travelcms2:HomePageBanner")
public class HomePageBanner extends BaseDocument {
HippoEssentialsGenerated(internalName = "travelcms2:title")
public String getTitle() {
return getProperty("travelcms2:title");
}
HippoEssentialsGenerated(internalName = "travelcms2:bannerimage")
public BannerImageSet getBannerimage() {
return getLinkedBean("travelcms2:bannerimage", BannerImageSet.class);
}
}
I uploaded a new image and created a document using my new document type, giving it a title and choosing my newly uploaded image. I saved and published my document.
I then in the Channel Manager add my carousel component to the page, and as the first carousel item I choose my new page and then publish the changes.
My problem is now that neither the title or image is being displayed on page. This is the resulting HTML snippit:
<div class="slide">
<p>>> <<</p>
</div>
And this is the error displayed in the log, where it indicates that the title property, which doesn’t have a null check, but does exist in my document, is “null or missing”.
[WARNING] [talledLocalContainer] %d{HH:mm:ss} WARN [HstFreemarkerServlet] Error in Freemarker template:
[INFO] [talledLocalContainer] freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
[INFO] [talledLocalContainer] ==> item.title [in template "webfile:/freemarker/eb/homepage-banner-short.ftl" at line 13, column 21]
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer] Tip: It's the step after the last dot that caused this error, not those before it.
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer] Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer] FTL stack trace ("~" means nesting-related):
[INFO] [talledLocalContainer] - Failed at: ${item.title} [in template "webfile:/freemarker/eb/homepage-banner-short.ftl" at line 13, column 19]
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer] at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) ~[freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:451) ~[freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:374) ~[freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:96) ~[freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.DollarVariable.accept(DollarVariable.java:59) ~[freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.Environment.visit(Environment.java:362) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:263) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:200) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.Environment.visitIteratorBlock(Environment.java:595) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:81) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.IteratorBlock.accept(IteratorBlock.java:67) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.Environment.visit(Environment.java:326) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.Environment.visit(Environment.java:332) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.Environment.visit(Environment.java:332) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.core.Environment.process(Environment.java:305) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.ext.servlet.FreemarkerServlet.processEnvironment(FreemarkerServlet.java:910) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.ext.servlet.FreemarkerServlet.process(FreemarkerServlet.java:879) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at freemarker.ext.servlet.FreemarkerServlet.doGet(FreemarkerServlet.java:764) [freemarker-2.3.24-incubating.jar:2.3.24]
[INFO] [talledLocalContainer] at org.hippoecm.hst.servlet.HstFreemarkerServlet.doGet(HstFreemarkerServlet.java:153) [hst-client-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) [servlet-api.jar:?]
[INFO] [talledLocalContainer] at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [servlet-api.jar:?]
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:8.5.34]
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.34]
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728) [catalina.jar:8.5.34]
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:591) [catalina.jar:8.5.34]
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:527) [catalina.jar:8.5.34]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstComponentInvokerImpl.invokeDispatcher(HstComponentInvokerImpl.java:443) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstComponentInvokerImpl.invokeRender(HstComponentInvokerImpl.java:250) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at sun.reflect.GeneratedMethodAccessor380.invoke(Unknown Source) ~[?:?]
[INFO] [talledLocalContainer] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]
[INFO] [talledLocalContainer] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.logging.HstComponentInvokerProfiler.profile(HstComponentInvokerProfiler.java:60) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at sun.reflect.GeneratedMethodAccessor250.invoke(Unknown Source) ~[?:?]
[INFO] [talledLocalContainer] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]
[INFO] [talledLocalContainer] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.PersistableSessionAroundAdvice.invoke(PersistableSessionAroundAdvice.java:68) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at sun.reflect.GeneratedMethodAccessor249.invoke(Unknown Source) ~[?:?]
[INFO] [talledLocalContainer] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]
[INFO] [talledLocalContainer] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) [spring-aop-4.3.15.RELEASE.jar:4.3.15.RELEASE]
[INFO] [talledLocalContainer] at com.sun.proxy.$Proxy117.invokeRender(Unknown Source) [?:?]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.AggregationValve.processWindowsRender(AggregationValve.java:449) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.AggregationValve.invoke(AggregationValve.java:252) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.ComponentRenderingValve.invoke(ComponentRenderingValve.java:34) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.PageCachingValve.invoke(PageCachingValve.java:62) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.ESIPageInfoScanningValve.invoke(ESIPageInfoScanningValve.java:80) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.PageInfoRenderingValve.invoke(PageInfoRenderingValve.java:50) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.ResourceServingValve.invoke(ResourceServingValve.java:40) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.ActionValve.invoke(ActionValve.java:47) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.LocalizationValve.invoke(LocalizationValve.java:101) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.ContextResolvingValve.invoke(ContextResolvingValve.java:115) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.JCRSessionStatefulConcurrencyValve.invoke(JCRSessionStatefulConcurrencyValve.java:56) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.SubjectBasedSessionValve.invoke(SubjectBasedSessionValve.java:58) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.SecurityValve.invoke(SecurityValve.java:177) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.CmsSecurityValve.invoke(CmsSecurityValve.java:88) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.InitializationValve.invoke(InitializationValve.java:49) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:288) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline.invokeValves(HstSitePipeline.java:173) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstSitePipeline.invoke(HstSitePipeline.java:155) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.core.container.HstRequestProcessorImpl.processRequest(HstRequestProcessorImpl.java:79) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.container.HstDelegateeFilterBean.processResolvedSiteMapItem(HstDelegateeFilterBean.java:671) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.container.HstDelegateeFilterBean.doFilter(HstDelegateeFilterBean.java:364) [hst-core-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.container.DelegatingFilter.doFilter(DelegatingFilter.java:84) [hst-commons-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.hippoecm.hst.container.HstFilter.doFilter(HstFilter.java:51) [hst-commons-5.3.0.jar:5.3.0]
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:8.5.34]
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.34]
I suspect the problem lies with my document type, because if I create another document with the default banner document type, which also has a title property and matching path, and add that document as the second item in my carousel, the title is being displayed on the page:
<div class="slide">
<p>>> <<</p>
<p>>> Test document <<</p>
</div>
Something else that might give a clue, is that when I change my template to print out “item”, instead of “item.title”, I get the following:
<div class="slide">
<p>>> org.hippoecm.hst.content.beans.standard.HippoDocument524d1f7 <<</p>
<p>>> com.eb.cms.travel.beans.Banner489c7f75 <<</p>
</div>
I suspect my problem lies with item in my new document type being “org.hippoecm.hst.content.beans.standard.HippoDocument”, but I have no idea why or how to resolve it. I see the same when adding debug to the page.
Lastly, I am able to get the title using an ugly workaround in my template:
${item.property["travelcms2:title"]}
This works for my document type, as well as the default banner type.
<div class="slide">
<p>>> Travel Sorted <<</p>
<p>>> Test document <<</p>
</div>
This is not something I want to resort to, and doesn’t work for compound fields like the image anyway.
Some other things I have tried without success is making a copy of the default banner document type, creating a document type with unique property paths not used in any other document type and inserting my document into a different single banner (not carousel) component.
Can anyone point me to where I have gone wrong please?