Listing 4: The Validation Business Logic
/**
* Validate the correct format of the personal identity number
* based on the selected identity type.
*
* @param mapping
* @param request
* @return action errors
*/
public ActionErrors validate( ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
errors = super.validate(mapping, request);
if (getPersonalIdentityNumber() != null
&& getPersonalIdentityNumber().length() > 0) {
// validate the number of the ABC PIN assigned by ABC Wireless Inc.
if (getSelectedPersonalIdentity().equals(ABC_PIN)) {
// validate the minimum number of the ABC PIN
if (getPersonalIdentityNumber().length() < 10) {
errors =addError(errors, ActionMessages.GLOBAL_MESSAGE,
"validator.abc.pin.invalid.minLength");
// validate the maximum number of the ABC PIN
} else if (getPersonalIdentityNumber().length() > 10) {
errors =
addError(
errors,
ActionMessages.GLOBAL_MESSAGE,
"validator.abc.pin.invalid.maxLength");
// validate the mask format of the ABC PIN
} else if (
!GenericValidator.matchRegexp(
getPersonalIdentityNumber(),
"^([A-Z]{1}[-]{1}[A-Z0-9]{3}[-]{1}[A-Z0-9]{4})$")) {
errors =
addError(
errors,
ActionMessages.GLOBAL_MESSAGE,
"validator.abc.pin.invalid.mask");
}
// validate the number of the DRIVER_LICENSE assigned by the local government.
} else if (getSelectedPersonalIdentity().equals(DRIVER_LICENSE)) {
// validate the minimum number of the DRIVER_LICENSE
if (getPersonalIdentityNumber().length() < 12) {
errors =
addError(
errors,
ActionMessages.GLOBAL_MESSAGE,
"validator.driver.license.invalid.minLength");
// validate the maximum number of the DRIVER_LICENSE
} else if (getPersonalIdentityNumber().length() > 12) {
errors =
addError(
errors,
ActionMessages.GLOBAL_MESSAGE,
"validator.driver.license.invalid.maxLength");
// validate the mask format of the DRIVER_LICENSE
} else if (
!GenericValidator.matchRegexp(
getPersonalIdentityNumber(),
"^([A-Z]{1}[0-9]{4}[-]{1}[0-9]{5}[-]{1}[0-9]{5})$")) {
errors =
addError(
errors,
ActionMessages.GLOBAL_MESSAGE,
"validator.driver.license.invalid.mask");
}
} else if (getSelectedPersonalIdentity().equals(IMMIGRATION_NO)) {
// TODO
} else if (getSelectedPersonalIdentity().equals(VETERAN_ID)) {
// TODO
} else if (
getSelectedPersonalIdentity().equals(OLD_AGE_SECURITY_NO)) {
// TODO
} else if (getSelectedPersonalIdentity().equals(PASSPORT_NO)) {
// TODO
} else if (
getSelectedPersonalIdentity().equals(REFUGEE_CLAIMANT_NO)) {
// TODO
} else if (
getSelectedPersonalIdentity().equals(SCOICAL_ASSISTANCE_NO))
// TODO
} else if (
getSelectedPersonalIdentity().equals(TREATY_STATUS_NO)) {
// TODO
} else if (getSelectedPersonalIdentity().equals(HEALTH_CARD_NO)) {
// TODO
} else if (
getSelectedPersonalIdentity().equals(BIRTH_CERTIFICATE_NO)) {
// TODO
}
}
return errors;
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.