englishteeth.co.uk

… the weblog of Ian “English Teeth” Robinson
  • rss
  • Home

Scoped Model Driven Interceptor

Ian | July 4, 2008

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…

Categories
development
Tags
freemarker, java, struts2
Comments rss
Comments rss
Trackback
Trackback

« Grails & JMS Revisited: Topic instead of Queue Autoboxing could catch you out »

2 responses

Try: #if (model.myproperty)?has_content WIthout the parentheses, it blows up if model is

Jonathan Revusky | July 4, 2008

Try:

#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, 2008

Thanks 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.

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Author

Ian Robinson is a relatively agile software engineer interested in things both sides of the object relational divide and beyond.

Categories

  • development (37)
  • miscellaneous (28)
  • music (7)
  • software (19)

What I'm Doing...

  • If I drink enough to see double will normal TV look 3D? 1 day ago
  • SLF - Here we go! 1 week ago
  • Quite a crowd of media outside Portsmouth's training ground and in the car park opposite this morning. 2 weeks ago
  • More updates...

Posting tweet...

Powered by Twitter Tools.

Blogroll

  • Dan North
  • Dave Astels
  • Dave Wood
  • eirikso.com
  • Matt Raible
  • Object Mentor Blog
  • The Ancient Art of Programming
  • The Wisdom of Ganesh

Tags

active-mq architecture bauhaus css db eclipse esb festivals freesat gorm grails groovy hd hibernate htpc java jboss jms junit links mce media center mini music oracle osgi patterns pirsig plugins satellite soa software spring sql struts2 testing themes tools tv vmc web wordpress xml xpath xslt
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox