• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Some questions about the Scoped Model Driven interface of Struts 2

 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm building a sample web application using Struts 2 (2.1.8.1) and am using the Scoped Model Driven interface (on my actions) to implement the Post-Redirect-Get (PRG) design pattern.

The documentation on the interface is pretty light, and after looking through a lot of information, I have a couple questions.

I had to provide parameter values to the ScopedModelDriven interceptor, which I did by including the following elements in the declarative architecture for my action (in struts.xml):
The documentation for the interface says that the className parameter is optional, and if not provided the data type will be taken from the type of the object returned by the action's getModel() method. However, I found that if I don't provide this parameter, the setScopeKey() method is called with "java.lang.Object" and the setModel() method is called with an object of type java.lang.Object.

Is this parameter actually required, or did I miss a configuration which would have make it optional?

Note that in my action class(es), nothing creates the Model object. The member variable is initialized to null, and the getObject() method just returns the current value (I believe I must not create a new instance of this object, even if the local member variable is null).

My second question has to do with the setScopeKey() method. Given that the model object is injected into my action, what's the point of having this key value? Is there a case where my action would still need to look up the object from the session (or wherever) scope map manually?

Thanks,
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Additionally, the getScopeKey() method never seems to be called. I thought that if I didn't include the name parameter to the interceptor, the framework would call this method to get the key name, but it didn't. Without the parameter set, the framework defaulted to the class name of the model object.

So, what is the getScopeKey() method for?
 
reply
    Bookmark Topic Watch Topic
  • New Topic