Follwing example of the ActionForm and action class will give u clear idea abt diff.
1.Validate method in the form
public ActionErrors validate(ActionMapping mapping, HttpServletRequest req) {
ActionErrors errors = super.validate(mapping, req);
if (guaranteeRequired == 1) {
//No Guest Guarantee
if ("".equals(planName)) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PPlDC_ValErrMsg_6"));
}
if ("".equals(otherPayNotes)) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PPlDC_ValErrMsg_1"));
}
if (!("".equals(receiveDate))) {
Date date = DateValidator.isValid(receiveDate,new Locale("EN_US"));
if (date == null) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PPlDC_ValErrMsg_5"));
receiveDate = "";
}
}
//Flag for checking "no guest guar required" in gpaytypevo
if ((amount != null) && !("".equals(amount))) {
double amountDouble = 0;
try {
amountDouble = Double.parseDouble(amount.trim());
} catch (NumberFormatException numEx) {
//Amount should be a numeric value
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PX_ERR_GP_AMOUNT"));
}
if ((amount.trim().length() > 10) || (amountDouble > 999999.99)) {
//Amount should be less that 10 characters and should not be greater than 999999.99
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PX_ERR_GP_AMOUNTRANGE"));
}
}
if ((referenceItem != null) && !("".equals(referenceItem))) {
int refItem = 0;
if (referenceItem.trim().length() > 40) {
//Reference Item should not be greater than 40 characters long
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PX_ERR_GP_REFITEM"));
}
try {
refItem = Integer.parseInt(referenceItem);
} catch (NumberFormatException numEx) {
//Reference Item should be a numeric value
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PX_ERR_GP_REFITEMNUME"));
}
if (refItem < 0) {
//Reference Item should be greater than zero
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PX_ERR_GP_REFITEMRANGE"));
}
}
if ((checkNumber != null) && !("".equals(checkNumber))) {
int checkNumInt = 0;
if (checkNumber.trim().length() > 40) {
//Check Number should not be greater than 40 characters long
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PX_ERR_GP_CHECKNUM"));
}
try{
checkNumInt = Integer.parseInt(checkNumber);
} catch (NumberFormatException numEx) {
//Check Number should be a numeric value
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PX_ERR_GP_CHECKNUMNUME"));
}
if (checkNumInt < 0) {
//Check Number should be greater than zero
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PX_ERR_GP_CHECKNUMRANGE"));
}
}
} else {
if (paymentByCC || paymentByNonCC) {
if ("".equals(guaranteePlanName)) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PPlDC_ValErrMsg_6"));
}
}
if (paymentByNonCC) {
if (!("".equals(dueDate))) {
Date date = DateValidator.isValid(dueDate,new Locale("EN_US"));
if (date == null) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PPlDC_ValErrMsg_3"));
dueDate = "";
} else {
dueDate = new SimpleDateFormat("MM/dd/yyyy").format(date);
}
}
if (!(numDaysDue.equals("")) || !(numDaysDue.length() == 0)) {
Pattern p = Pattern.compile("[0-9]+");
//Match the given string with the pattern
Matcher m = p.matcher(numDaysDue.trim());
//check whether match is found
boolean matchFound = m.matches();
if (!matchFound) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("PPlDC_ValErrMsg_4"));
}
}
}
}
if (errors.size() > 0) {
validationErrors = true;
} else {
validationErrors = false;
}
return errors;
}
2. Action class method using save error in the exception class.
public ActionForward remove(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
logger.entering();
List paymentPlanList = null;
ActionErrors errors = new ActionErrors();
GuaranteePaymentForm paymentForm = (GuaranteePaymentForm) form;
try {
ResdeskSessionManager session = ResdeskPageAction.getResdeskSessionManager(request );
PKComponentRequestVO requestVO = session.getPKComponentRequestVO();
PKResdeskXDelegate pkResdeskXDelegate = new PKResdeskXDelegate();
if (ResdeskPageAction.checkAndTouchLogin(request, response,
PasskeyUtils.getResDeskAppID().intValue())) {
return null; // session has expired
}
requestVO.setComponentTypeId(PKComponentRequestVO. GUARANTEE);
String paymentPlanIdStr = request.getParameter("paymentPlanId");
if (paymentPlanIdStr != null) {
int paymentPlanId = new Integer(paymentPlanIdStr).intValue();
requestVO.setComponentId(paymentPlanId);
pkResdeskXDelegate.remove(requestVO, new GuaranteePlanCVO());
}
paymentPlanList = pkResdeskXDelegate.listByEvent(requestVO);
session.putSessionData(ConstantDeclareI.GUARANTEEP LANLIST,
paymentPlanList);
AccessPrivilegeVO accessPriviligeVO = pkResdeskXDelegate.getAccessPrivileges(requestVO);
request.setAttribute(ConstantDeclareI.PAYMENTPLAN_ ACCESSPREVILEGE,
accessPriviligeVO);
} catch (Exception exp) {
paymentForm.setValidationErrors(true);
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError(exp.getMessage()));
saveErrors(request, errors);
}
logger.exiting();
return mapping.findForward("planlist");
}
Thanks and Regards,
SACHIN S.TATHOD
Patni Computer System Ltd.
Magarpatta City, Cyber City,
Tower 3,Level I & II,
Hadapsar,Pune - 411028
Mobile No:- +91-9881239401
Email ID:-
[email protected]