• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

User Id validation problem on JSP page

 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic