Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Struts2 - scopedModelDriven

Posted on 2010-09-16
4
Medium Priority
?
2,184 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 2000 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

705 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