This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Moving a bean from request to session context

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using JavaBeans to handle HTML form submissions, and have things set up so that an initial form submits to a validation page, which creates a JavaBean in request scope from the parameters in the request. This page uses the bean to do some validation, and then does one of two things:
1. If everything is valid it forwards to a confirmation page, which uses the information in the bean to reprint the entered values (this page has access to the bean because it is forwarded).
2. If there is a problem, it uses the bean to print out errors and redisplay the form, with all previously entered values intact.
Here is a picture of the flow:
form.jsp
|
| (VIA FORM ACTION)
|
V
validate.jsp
|
| (VIA FORWARD)
|
V
confirmation.jsp
Now my problem: I want to put something on the confirmation page that says "Is this correct?" and allow the user to go back to the initial form page if it is not. However, I would like this initial page to be populated with the values already entered, again using the JavaBean.
In order to accomplish this, I would like to move the bean from request scope to session scope, and then have the initial page look for it there. If possible, I would like to have the initial page simply have a useBean tag that locates the bean.
So, after all this, my question: is there a way to manually put a bean in session scope so that a useBean tag can find it?
Thanks...
Buzz Andersen
 
Buzz Andersen
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, a little experimentation has led me to just adopt a practice of putting the bean in session scope across the board, rather than trying to move the bean over from request scope. Now I have another question:
When the bean gets updated by the "jsp:setProperty name='x' value='*'" in validate.jsp, the fields only get updated if there is something in them. If, for example, I delete the text completely from a text field and then resubmit, the setter method for that property is not called and the old value remains. I can change the text in the field--as long as there is something there the setter method gets called. But if the field is blank, it keeps its old value.
Does anyone know of a good way around this problem? I thought about writing a Javascript that submits "null" values or something if it finds that form fields are blank, but I'd rather not do it that way...
Perhaps this behavior is simply a good reason to do things the way I was originally planning (i.e. doing everything in request context and only moving to session context when necessary).
Thanks again...
Buzz
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic