Solved

Struts2 - scopedModelDriven

Posted on 2010-09-16
4
2,134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

622 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