-
Jul 19th, 2011, 03:15 PM
#1
passing object from listener to doPost using SessionAttributes
Hi
Here is my servlet myApp. For incoming GET request, myAppForm will be displayed for user to enter student name. Once student name is entered, POST method is called ,ProcessMyAppRequest. In ProcessMyAppRequest, student name is extracted from object StudentObject (POJO). I also have instance AppEventlListener listen for some kind of event. If the event is happening, I will return student's age in myAppFormSuccess. MyAppFormSuccess needs to access StudentObject.age for display result.
My questions are:
1. Since I have AppEventListener in doPost, how do I assign age to student in its update method and return to doPost where MyAppFormSuccess will be able to access StudentObject.age?
2. In the update function of AppEventListener below, how do I assign age to same StudentObject from doPost. Is SesssionAttributes ("StudentObject") a solution?
Thanks a lot for your help
@Controller
@RequestMapping("/myApp")
public class MyAppController {
@RequestMapping(method = RequestMethod.GET)
public String showMyAppRequest(Map<String, StudentObject> model) {
StudentObject studentObject = new StudentObject();
model.put("studentObject", studentObject);
return "myAppForm";
}
// Process the user input from myAppForm .
@RequestMapping(method = RequestMethod.POST)
public String processMyAppRequest(@Valid StudentObject studentObject,
BindingResult result, Map<String, StudentObject> model) {
if (result.hasErrors()) {
return "myAppForm";
}
model.put("studentObject", studentObject);
new AppEventListener("Some Event");
return "myAppFormSuccess";
}
@SessionAttributes("studentObject")
private class AppEventListener extends GenericEventListener {
public AppEventListener (String msg) {
super (msg);
MessageObserver obMessage = MessageObserver();
synchronized(this) {
obMessage.addListener(msg);
}
}
public void update (final Observable listener, final Object msg) {
if (msg == "Some Event") //Event is happening
/* QUESTION
How do I access studentObject and assign StudentObject.age so when I return to doPost, myAppFormSuccess will display this age.
}
}
------------ StudentObject ---------
public class StudentObject {
String student = null;
int age;
public setStudentName (String student){
student = student;
}
public getStudentName(){
return student;
}
public setStudentAge (int age){
age = age;
}
public int getStudentAge(){
return age;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules