Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request attributes missing

 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !?
 
Mark Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic