File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

maxlength for customer id column

 
Tim Fernandez
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 288
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11831
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any thoughts on how to implement this one?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11831
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic