Scoped Model Driven Interceptor
In 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…