• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Validation in update, create methods

 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How much validation is required in the update and create methods?
(URLyBird 1.2.1)
Currently, I have the following:
a) If incoming data is longer than allowed field length, throw IllegalArgumentException.
b)If incoming data is null, I set it to an empty String
Should I also be doing the following types of validation?
1. Don't allow updates to an empty String (i.e. null input field)
2. Make sure size field is numeric
3. Verify smoking is "Y" or "N"
4. Rate does not include any letters (only allow currency symbol and decimal point)
5. Validate for a valid date
6. Customer id is numeric
Is this too much validation, or are there any other types of validation I'm missing here?
Thanks.
TJ
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have any ideas on this?
TJ
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Terry,
(URLyBird 1.2.1)

Same as mine !
a) and b) both look reasonable.
Should I also be doing the following types of validation?
1. Don't allow updates to an empty String (i.e. null input field)
2. Make sure size field is numeric
3. Verify smoking is "Y" or "N"
4. Rate does not include any letters (only allow currency symbol and decimal point)
5. Validate for a valid date
6. Customer id is numeric
Is this too much validation, or are there any other types of validation I'm missing here?

6. is OK, and you'll have to check it in your business layer (client-side or server-side). But for 1-5, you cannot do anything : Data is not aware of field types, and your application as a whole never updates other fields but the owner one.
Regards,
Phil.
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Phil - I'll go with that
TJ
 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
6. is OK, and you'll have to check it in your business layer (client-side or server-side). But for 1-5, you cannot do anything : Data is not aware of field types, and your application as a whole never updates other fields but the owner one.
Does that mean we only need to validate the owner field?
IMO, Validate 1-5 is better but is not necessary. "You will not receive extra credit points for work beyond the requirements of the specification. " Anyone has a different or better idea?
Peter
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think validating anything but the record field is over doing it.
Why? Sun wanted us to implement booking and THATS IT. The rest
of the functionality can be left in the Data class. And as Phil
mentioned you should not be doing any type of validating in Data.
In fact you may loose points over this
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill -

I think validating anything but the record field is over doing it.

Are you referring to the record number field, and a RecordNotFoundException in your quote above?
My specs say that the customer id/owner field should be an 8 digit number, so I think that validating it is fair and would meet the requirements without overdoing it.
I plan to skip the 1-5 validation mentioned above as per Phil and Bill's suggestion.
TJ
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic