• 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

keeping a form beans state across a jsp without hidden fields

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

After a long time away from struts im back in with a bang and seem to have forgotten all the old tricks.

Anyway what im wondering is how to to keep a form beans state across a JSP without using hidden fields.

For example if i i create a large form bean but only have a select for one preoperty in the JSP when it comes back to my next action class after submit all the state will be gone. except for that one variable.

is there a clean way of getting round this?

thanks

David
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest way around this is simply to put the form bean in session scope, rather than request scope.

I know many developers gasp with shock the moment you suggest putting anything in the session, but in my mind if the bean doesn't contain a large amount of data, the performance of the site will not be aversely affected by putting a form bean in session scope. It often outweighs the problems associated with putting sensitive data in hidden fields on the form where they can be viewed and spoofed.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My issue with configuring actions to use session scope is not with storing one form in session...it is with the build up that would occur if you made this common practice. Each user could have hundreds of forms in session.

The "solution" that I developed for my project was to use a limited number of "slots" on the session to store forms. For example, there is one name that gets used for saving edit forms to the session. That way you can save forms to the session without being worried about too many forms building up on the session.

Here are the simple get and set methods for the "last edit form":


- Brent
 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think thats a fairly clean way of doing it brent. the cleanest way i can seen so far. ive no objection to using the session for form beans its just that ive seen so many abuses of the session in struts apps.

i just thought struts could have handled it it a better way. its been nearly 4 years since using struts in a big way and i thought that issue might have been tackled in that time.

i think dumping stuff on the session makes the whole visulisation of the front end more difficult as you dont always know where the object has came from.

people always have a SessionHelper class and you always find about 5 uses more of the setThisFormBean than the getThisFormBean methods. debugging just goes out of the window as you dont know where the object originated.

anyway its friday.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic