This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes maxlength for customer id column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "maxlength for customer id column" Watch "maxlength for customer id column" New topic
Author

maxlength for customer id column

Tim Fernandez
Ranch Hand

Joined: Aug 31, 2005
Posts: 65
Hi Everyone,

I would like to limit the number of string that can be entered in the customer id field. In this case, i will only allow 8 characters since this is what the urly bird specification requires. ANy thoughts on how I can implement this one?

regards,
tim
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
In your create and update methods you could compare the length of the String provided against the metadata for each field.

Then if a field is too long you can either throw an exception or you could choose to truncate the string, i.e only insert the x leftmost characters.

Jason.
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
Why not have an InputValidator class and restrict the length. This way, you only need to do it in one location, not in every SQL statements


java j2ee job interview questions with answers | Learn the core concepts and the key areas
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Have you looked at what formatted text fields can do for you? Especially the javax.swing.text.MaskFormatter class?

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Tim Fernandez
Ranch Hand

Joined: Aug 31, 2005
Posts: 65
Hi Everyone,

I'm sorry about the confusion. I am entering the customer id in the cell in the table. So i do not think Maskformatter will help me. So I am wondering if there is something in the cell that can limit the number of characters you can enter.

regards,
tim

Originally posted by Andrew Monkhouse:
Have you looked at what formatted text fields can do for you? Especially the javax.swing.text.MaskFormatter class?

Regards, Andrew
Tim Fernandez
Ranch Hand

Joined: Aug 31, 2005
Posts: 65
Any thoughts on how to implement this one?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Tim,

I have condensed Sun's TableFTFEditDemo into what is possibly the smallest bit of code that I can use to discuss this - it creates a simple table where the third column will only allow integers between 100 and 999 to be entered.

See how you go with this and/or see how you go with Sun's tutorials on the subject.

If in doubt, you can always come back and ask questions

Regards, Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: maxlength for customer id column
 
Similar Threads
How to return nicely?
not getting what this servlet is doing+MVC
What's this meaning?
Bodgitt and Scarper GUI requirements
Newbie validation with textfile