I'm building a sample web application using Struts 2 (184.108.40.206) 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?
Mark E Hansen
Joined: Apr 01, 2009
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.