• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Request attributes missing

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic