It's not a secret anymore!*
The moose likes JSP and the fly likes User Id validation problem on JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "User Id validation problem on JSP page" Watch "User Id validation problem on JSP page" New topic
Author

User Id validation problem on JSP page

Tariq Ahsan
Ranch Hand

Joined: Nov 03, 2003
Posts: 116
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

Joined: Jan 10, 2002
Posts: 61657
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tariq Ahsan
Ranch Hand

Joined: Nov 03, 2003
Posts: 116
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

Joined: Nov 03, 2003
Posts: 116
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

Joined: Jan 10, 2002
Posts: 61657
    
  67

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

Joined: Jan 10, 2002
Posts: 61657
    
  67

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

Joined: Nov 03, 2003
Posts: 116
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: User Id validation problem on JSP page