• 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

User Id validation problem on JSP page

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

I am a JSP newbie. I am trying to create a JSP page for a new user profile creation. After the user enters all the required personal data he/she has to choose an user id and password. When the user hits the submit button the page calls an existing bean to verify if the user id already exists in the database. If the id already exists it will display a message on the page saying 'User already exists ...' and will blank both the user id and password fields. But rest of the other the user's data should remain visible. I have been somewhat able to display the message if the user id already exists on a new page. But the other input data is getting lost. Is it possible to stay on the same page and do this sort of user id validation? Wondering what is the best way to do this overall? Any hint with code snippet would help me greatly.

Thanking you.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using a traditional method, in other words submitting the whole page, you can restore the original values in the fields by using their value attributes and setting them to the submitted values.

A more modern, but complicated approach, is to use Ajax to perform the validation behind the scenes. Taking this route means that you'll really have to bone up on your JavaScript and other client-side technologies like CSS.
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just one thought. As I have 8/10 fields for the personal data input. Should I have a hidden field for each of these and copy the input data in these hidden fields? Then later when the same page is refreshed then get these data back into the actual field? It would be helpful to know how I can copy data into hidden fields and re-populate back the actual fields with the same data. Is this one way of doing what I want to do?

Thanks
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

Thanks for your really prompt response. Is there a code snippet I can use for what you are suggesting? It surely would help a newbie like me?

Thanking you again.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tariq Ahsan:
Should I have a hidden field for each of these and copy the input data in these hidden fields?


What would that accomplish? If you know how to set the values of the hidden fields, you can just set the visible field values.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tariq Ahsan:
Is there a code snippet I can use for what you are suggesting?


Which approach?

For the traditional route, something like:


The EL expression in the value attribute captures the submitted value and makes it the initial value of the field. If the parameter doesn't exist, it will be blank so everything's cool first time around.
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

Can't thank you enough!. I'll try out what you suggested. Yes, I think I will have to do things in the traditional way.
 
It's a tiny ad only because the water is so cold.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic