| Author |
Request attributes missing
|
Leandro Melo
Ranch Hand
Joined: Mar 27, 2004
Posts: 401
|
|
Suppose a user submits a request that is handled by MyActionDoSomething. Then this action sets a request attribute like this: request.setAttribute("MyObject", obj); and forwards the request to the page myPageDoSomeOtherThing.jsp, wich has some inputs for the user to fill in. This page (myPageDoSomeOtherThing.jsp) uses the bean "obj" that was set in MyActionDoSomething.java ok !? Now suppose the user submits wrong information in myPageDoSomeOtherThing.jsp, what will cause the validate method in the associated ActionForm to return some ActionErrors. BUT when the ActionForm send this page back for the user to re-input data, the bean "obj" that was set at the very beginning in MyActionDoSomething.java is NOT present anymore! I think now it's clear that i'm not talking about the formBean attributes, right !?
|
Leandro Melo <br />SCJP 1.4, SCWCD 1.4<br /><a href="http://www.pazbrasil.org/" target="_blank" rel="nofollow">http://www.pazbrasil.org/</a>
|
 |
Mark Jones
Greenhorn
Joined: Apr 30, 2004
Posts: 4
|
|
|
It sounds like you may have a different session the second time around. Print out the session.getId() each time the page loads.... check to make sure you have the same session.
|
 |
Junilu Lacar
Bartender
Joined: Feb 26, 2001
Posts: 4115
|
|
A few things you can do (there may be other approaches): 1. Put the obj bean in the session context or application context instead. or 2. Before returning from the validate method, put the obj bean in the request context again. or 3. Make obj a form attribute instead. You can use <html:hidden> tags as needed to ensure that the initial values of obj are repopulated in the event of validate-errors-reinput. [ August 13, 2004: Message edited by: Junilu Lacar ]
|
Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
|
 |
Junilu Lacar
Bartender
Joined: Feb 26, 2001
Posts: 4115
|
|
Originally posted by chughead: It sounds like you may have a different session the second time around. Print out the session.getId() each time the page loads.... check to make sure you have the same session.
The session is the same. It's the request context that's new. Remember, as soon as the initial request (the one that had obj in context) has been processed and obj has been used to generate the response, the request, and the obj bean with it, goes away. When the form is submitted, a new request is being processed. This new request will not have the obj bean unless you explicitly put it in the request context again.
|
 |
Leandro Melo
Ranch Hand
Joined: Mar 27, 2004
Posts: 401
|
|
A few things you can do (there may be other approaches): 1. Put the obj bean in the session context or application context instead. In my case, this object cannot be in Sesison context. 2. Before returning from the validate method, put the obj bean in the request context again. Sounds nice and it would actually work because the page (diferent pages from the same Tiles definition) keeps track of this objects. There's only one point: It' not only one object, they're 3. I took a look at the ServletContext api and noticed a "getParameterMap()" with returns all the parameters, but it's too sory not having a "setParameterMap()". Would make things easier. 3. Make obj a form attribute instead. You can use <html:hidden> tags as needed to ensure that the initial values of obj are repopulated in the event of validate-errors-reinput. I don't like this one very much, seems like a polution in the formbeans. Another option sugested by other people was to set the input of this ActionForma as the Action that really sets all these parameters. Thanks Junilu. [ August 13, 2004: Message edited by: Leandro Melo ]
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
Another option sugested by other people was to set the input of this ActionForma as the Action that really sets all these parameters.
That's the way to go. Use a simple populate action.
|
A good workman is known by his tools.
|
 |
 |
|
|
subject: Request attributes missing
|
|
|