Scoped Model Driven Interceptor
Ian | July 4, 2008In my struts 2 project, I have an action that implements the ScopedModelDriven interface.
I have configuration that references the ScopedModelDrivenInterceptor with a session scope…
<interceptor name="scoped-model-driven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"> <param name="scope">session</param> </interceptor>
My action references this interceptor and specifies the key used when the object was previously put in the session.
<interceptor-ref name="scoped-model-driven"> <param name="name">session-key</param> </interceptor-ref>
This all works fine, except in my freemarker templates I now need to reference model.myproperty, rather than just property.
I could live with that, but unfortunately
<#if myproperty?has_content> ...
no longer returns any results and worse
<#if model.myproperty?has_content> ...
blows up completely!
javax.servlet.ServletException: ?size is unsupported for: freemarker.ext.beans.SimpleMethodModel
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
I’ve tried a few variations of reference to no avail.
Very disappointing.
The reason I’m writing this up is that the scoped model driven thing looked almost exactly how I wanted to go with these actions, so I want to remember where I got to, but getting it working is more important.
Back to ModelDriven, SessionAware and Preparable…






Try: #if (model.myproperty)?has_content WIthout the parentheses, it blows up if model is
Jonathan Revusky | July 4, 2008Try:
#if (model.myproperty)?has_content
WIthout the parentheses, it blows up if model is undefined.
Thanks Jonathan. In this case model was defined and it was
Ian | July 7, 2008Thanks Jonathan.
In this case model was defined and it was referenced successfully elsewhere in the template.
${(model.title)!} - no problem.
It seemed to be the directive or perhaps just the collection reference such as
< #if model.mycollection?has_content>that caused it to fail with the above stack trace.
And only with the Scoped Model Driven Interceptor. It’s curious…
I’ll dig further when I get the chance.