Solved

Struts2 - scopedModelDriven

Posted on 2010-09-16
4
2,030 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 128
GUI builder for Eclipse? 8 27
Apps blocked by Java 9 55
table example 4 19
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now