Solved

Struts2 - scopedModelDriven

Posted on 2010-09-16
4
2,051 Views
Last Modified: 2013-11-24
Hi,
I want to know how to make scopedModelDriven work in Struts2.

Currently I am imlementing ModeDriven in my Action. But I want to have my model class scope throughout the session, so i can use its Object in any action. Please let me know how to make this work either using scopedModelDriven or anything else.

Thanks
0
Comment
Question by:shetty01
4 Comments
 
LVL 1

Accepted Solution

by:
Suresh Kumar S earned 500 total points
ID: 33796899
Follow the below steps to implement ScopedModelDriven in Struts2.

Add the below interceptor reference in Struts.xml:

<interceptor name="myScopeModInt" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor">
  <param name="scope">session</param>
  <param name="name">user</param>
  <param name="className">com.scopetest.entity.UserDetails</param>        
</interceptor>


Add the below entries in your action mapping XML:

<action ....

<interceptor-ref name="scopedModelDriven">
  <param name="scope">session</param>
  <param name="name">userDetail</param>
  <param name="className">com.scopetest.entity.UserDetails</param>    
</interceptor-ref>

....
</action>


Implement ScopedModelDriven interface in you Action class and create accessor methods for the POJO UserDetails in your action class.

public class MyScopedTestAction extends ActionSupport implements ScopedModelDriven,Preparable {

  private UserDetails userDetails = new User();

  public void setModel(UserDetails userDetails) {
         this.userDetails = userDetails;
  }

  public Object getModel() {
    return userDetails;
  }

  public UserDetails getUserDetails() {
    return userDetails;
  }

  public void setUserDetails(UserDetails userDetails) {
    this.userDetails = userDetails;
  }

...

}

Now you can use the user details bean throughout the session.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 56
jdbc error in jsp application 20 63
by zero exception 10 52
Java 8 to Java 6 8 20
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question