Solved

Struts2 - scopedModelDriven

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 82
IT Company 5 69
Impossible to extract MSI from new JAVA releases 2 38
Java Jpanels and Jframe 8 20
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

708 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

16 Experts available now in Live!

Get 1:1 Help Now