It's not a secret anymore!*
The moose likes Struts and the fly likes Some questions about the Scoped Model Driven interface of Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Some questions about the Scoped Model Driven interface of Struts 2" Watch "Some questions about the Scoped Model Driven interface of Struts 2" New topic
Author

Some questions about the Scoped Model Driven interface of Struts 2

Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
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

Joined: Apr 01, 2009
Posts: 643
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Some questions about the Scoped Model Driven interface of Struts 2