RE: Struts2 - ScopedModelDriven - Unable to update the model and set the latest Model data in session

2009-09-08 Thread Raghuveer.V
This is working after using correct jar file, "struts2-core-2.1.6" jar.

 

  _  

From: Raghuveer.V [mailto:raghuve...@infotechsw.com] 
Sent: Wednesday, August 19, 2009 6:55 PM
To: 'user@struts.apache.org'
Subject: Struts2 - ScopedModelDriven - Unable to update the model and set
the latest Model data in session 

 

Hi,

 

I have a problem implementing ScopedModelDriven.

 

 

I Have Model / User Java Bean object in action class.

 

I am trying to implement concept of same model object being used for 3 JSP
pages with PREVIOUS and NEXT button navigation.

Data to be updated in Model object for every page navigation and to be saved
in session.

It is found the latest data is found from value stack when jsp page is
navigated to next page, but not updated in Model object either in request or
session scope 

I am sure I have configured necessary interceptors properly.

 

This could be easily done in struts1 by setting the Actionform in session
scope.

Any advice or thought?.

 

 

Struts.xml:

 



http://struts.apache.org/dtds/struts-2.0.dtd";>













 session

 user

  com.ut.p.s2.beans.User 

   



 



/jsp/Error.jsp

/jsp/Error.jsp

/jsp/login.jsp



 







 



 



/jsp/smodelTest.jsp

/jsp/smodelTest.jsp















session

user

com.ut.p.s2.beans.User









/jsp/smodelTest.jsp

/jsp/smodelResult.jsp

/jsp/smodelTest.jsp

/jsp/smodelTest2.jsp

/jsp/smodelTest3.jsp 

/jsp/smodelResult.jsp 







 

 

 

Action:

 

package com.ut.p.s2.actions;

import java.util.ArrayList;

import com.ut.p.s2.beans.Books;

import com.ut.p.s2.beans.Dept;

import com.ut.p.s2.beans.User;

import com.opensymphony.xwork2.ActionSupport;

import com.opensymphony.xwork2.Preparable;

import com.opensymphony.xwork2.interceptor.ScopedModelDriven; 

 

public class ScopedModelDrivenAction extends ActionSupport implements
ScopedModelDriven,Preparable {

 

private User user =null;

private static final long serialVersionUID =
1271130427666936592L;

private String scope = null;

 

public void prepare() throws Exception {

user = new User();

ArrayList arlList=new ArrayList();

Books b1 = new Books("Java",100);

Books b2 = new Books("VB",200);

arlList.add(b1);

arlList.add(b2);



Dept dept = new Dept();

dept.setDeptNo("100");

dept.setDeptName("Mechanical");

user.setDept(dept);

user.setArlList(arlList);

}

 

public String getScopeKey() {

return scope;

}

 

public void setModel(Object arg0) {

this.user = (User) arg0;

}

 

public void setScopeKey(String arg0) {

 scope = arg0;

}

public Object getModel() {

 return user;

}

 

/**

 * @return the user

 */

public User getUser() {

return user;

}

 

/**

 * @param user the user to set

 */

public void setUser(User user) {

this.user = user;

}





public String execute() {

System.out.println("execute()."+user);

return INPUT;

}



public String input() throws Exception {

System.out.println("input()."+user);

return SUCCESS;

}



public String save() {

System.out.println("save()."+user);

return "model_result_page";

}



public String page1() {

System.out.println("page1()."+user);

System.out.println("page1()scope."+scope);

return "model_test_page";

}



public String page2() {

System.out.println("page2()."+user);

System.out.println("page2()scope."+scope);

return "model_test_page2";

}

 

public String page3() {

System.out.println("page3()."+user);

System.out.println("page3()scope."+scope);

return "model_test_page3";

}

 

}//end class

 

Java Beans:

 

package com.ut.p.s2.beans;

 

import java.util.ArrayList;

 

public class User {

 

 

Re: Struts2 - ScopedModelDriven - Unable to update the model and set the latest Model data in session

2009-08-25 Thread Stephen Turner
On Wed, 19 Aug 2009 09:24:52 -0400, Raghuveer.V  
 wrote:



Hi,



I have a problem implementing ScopedModelDriven.



One thing that could be a problem:



public void prepare() throws Exception {
user = new User();


Don't instantiate a new User object - the interceptor will do that the  
first time, and will pull the object out of session after that, and inject  
it into your action class.



Steve

--
Stephen Turner
Senior Programmer/Analyst - SAIS
MIT IS&T

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Struts2 - ScopedModelDriven - Unable to update the model and set the latest Model data in session

2009-08-19 Thread Raghuveer.V
Hi,

 

I have a problem implementing ScopedModelDriven.

 

 

I Have Model / User Java Bean object in action class.

 

I am trying to implement concept of same model object being used for 3 JSP
pages with PREVIOUS and NEXT button navigation.

Data to be updated in Model object for every page navigation and to be saved
in session.

It is found the latest data is found from value stack when jsp page is
navigated to next page, but not updated in Model object either in request or
session scope 

I am sure I have configured necessary interceptors properly.

 

This could be easily done in struts1 by setting the Actionform in session
scope.

Any advice or thought?.

 

 

Struts.xml:

 



http://struts.apache.org/dtds/struts-2.0.dtd";>













 session

 user

  com.ut.p.s2.beans.User 

   



 



/jsp/Error.jsp

/jsp/Error.jsp

/jsp/login.jsp



 







 



 



/jsp/smodelTest.jsp

/jsp/smodelTest.jsp















session

user

com.ut.p.s2.beans.User









/jsp/smodelTest.jsp

/jsp/smodelResult.jsp

/jsp/smodelTest.jsp

/jsp/smodelTest2.jsp

/jsp/smodelTest3.jsp 

/jsp/smodelResult.jsp 







 

 

 

Action:

 

package com.ut.p.s2.actions;

import java.util.ArrayList;

import com.ut.p.s2.beans.Books;

import com.ut.p.s2.beans.Dept;

import com.ut.p.s2.beans.User;

import com.opensymphony.xwork2.ActionSupport;

import com.opensymphony.xwork2.Preparable;

import com.opensymphony.xwork2.interceptor.ScopedModelDriven; 

 

public class ScopedModelDrivenAction extends ActionSupport implements
ScopedModelDriven,Preparable {

 

private User user =null;

private static final long serialVersionUID =
1271130427666936592L;

private String scope = null;

 

public void prepare() throws Exception {

user = new User();

ArrayList arlList=new ArrayList();

Books b1 = new Books("Java",100);

Books b2 = new Books("VB",200);

arlList.add(b1);

arlList.add(b2);



Dept dept = new Dept();

dept.setDeptNo("100");

dept.setDeptName("Mechanical");

user.setDept(dept);

user.setArlList(arlList);

}

 

public String getScopeKey() {

return scope;

}

 

public void setModel(Object arg0) {

this.user = (User) arg0;

}

 

public void setScopeKey(String arg0) {

 scope = arg0;

}

public Object getModel() {

 return user;

}

 

/**

 * @return the user

 */

public User getUser() {

return user;

}

 

/**

 * @param user the user to set

 */

public void setUser(User user) {

this.user = user;

}





public String execute() {

System.out.println("execute()."+user);

return INPUT;

}



public String input() throws Exception {

System.out.println("input()."+user);

return SUCCESS;

}



public String save() {

System.out.println("save()."+user);

return "model_result_page";

}



public String page1() {

System.out.println("page1()."+user);

System.out.println("page1()scope."+scope);

return "model_test_page";

}



public String page2() {

System.out.println("page2()."+user);

System.out.println("page2()scope."+scope);

return "model_test_page2";

}

 

public String page3() {

System.out.println("page3()."+user);

System.out.println("page3()scope."+scope);

return "model_test_page3";

}

 

}//end class

 

Java Beans:

 

package com.ut.p.s2.beans;

 

import java.util.ArrayList;

 

public class User {

 

private String name;

private int age;

private String sex;

private String[] hobby;

private String country;

private ArrayList arlList;



private Dept dept=new Dept();

 

public String getName() {

return name;

}

 

public void setName(String name) {

this.name = name;

}

 

public int getAge() {

return age;

}

 

public void setAge(int age) {

this.age = age;

}

 

public String getSex() {

return sex;