• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Redisplay Variables in JSP after Failed Validation?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp that contains a name (populated from database) and a blank email field. When the user presses the submit button, I validate the email and send it back to the jsp page if it fails.

How am I supposed to redisplay the name? I have been placing it into a session variable, but is that the only/best way? What if I have a lot of variables (name, address, phone, arrays)?


The entire app:
1. jsp -- User enters ID
2. action -- grab name from database based on ID and place in session variable
3. jsp -- display name and ask for email
4. action -- validate email
5. jsp -- display name (problem here), ask for email, display validation error
[ August 09, 2005: Message edited by: David Martin ]
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keeping the name in session is not better idea if it is just required to display back. If you want to have this variable thru out application in different pages you can keep it in session. Other wise just use HttpRequest method getAttribute() and setAttribute() to share the name.

If you have more than one variable then you can create a java bean classes with all properties of name, address, phone. And share that java bean between the pages.

Hope it helps you.
[ August 09, 2005: Message edited by: KJ Reddy ]
 
David Ogasawara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the response! Unfortunately, using HttpRequest does not work. I can initially get it to display the name in the jsp, but after a failed validation, the redisplayed jsp is blank.


EmailAction: get name from database
email.jsp: display name, email field (form action="email")
EmailAction: validate emailAddress (failed) ---> mapping.findForward("failure")
XML: <forward name="failure" path="/email.jsp"/>
email.jsp: name not displayed, email field, error message


I will continue to experiment.
 
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
When you display (as in text-only) a variable like that, you need to also set it with a html:hidden tag to propogate across validation.
 
David Ogasawara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So that's how you do it!!!

THANK YOU!!!

I'm going to print the page and nail it to my wall.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic