|
hi,
struts validator provides both client side as well as server side
validations.
if u want to use the serverside validations , u have to extend the
validatorForm instead of ActionForm and remove the validate() method all
together.
but, in my application, i am using validator for client side
validations and on the server side i still use plain vanilla Action forms
and validation method (for validations) for my own business
requirements.
so its a matter of choice.
--nagi
-------Original Message-------
Date: Thursday, July
10, 2003 11:42:11 AM
Subject: What should be
in validate() method when using struts validator package
What should be in validate() method when we use Struts
Validator package? Should it be an empty method?
My current
validate() method (without using Struts Validator) is as follows:(What
should it be if I implement validations in validator-rules.xml and
validations.xml)? Pl. suggest.
public ActionErrors
validate(ActionMapping mapping, javax.servlet.http.HttpServletRequest
request) { // maintenance forms do new, update and delete, but also
searches and create new for // fkey resolvers. Only new and update
actually need validation. if (!lrAction_.equals("New") &&
!lrAction_.equals("Update")) return null;
ActionErrors errs = new
ActionErrors(); SupportValues support = new
SupportValues();
try
{ support.setContactName(contactName_); } catch
(IllegalArgumentException ex) { errs.add(FLD_CONTACT_NAME,new
ActionError("supportviewform.error_contact_name",ex.getMessage())); } try
{ support.setContactDetail(contactDetail_); } catch
(IllegalArgumentException ex) { errs.add(FLD_CONTACT_DETAIL,new
ActionError("supportviewform.error_contact_detail",ex.getMessage())); } try
{ support.setPhoneNo(phoneNo_); } catch (IllegalArgumentException
ex) { errs.add(FLD_PHONE_NO,new
ActionError("supportviewform.error_phone_no",ex.getMessage())); } try
{ support.setEmailAddr(emailAddr_); } catch
(IllegalArgumentException ex) { errs.add(FLD_EMAIL_ADDR,new
ActionError("supportviewform.error_email_addr",ex.getMessage())); } try
{ support.setSubject(subject_); } catch (IllegalArgumentException
ex) { errs.add(FLD_SUBJECT,new
ActionError("supportviewform.error_subject",ex.getMessage())); } try
{ support.setMessage(message_); } catch (IllegalArgumentException
ex) { errs.add(FLD_MESSAGE,new
ActionError("supportviewform.error_message",ex.getMessage())); } if
(errs.empty()) return null;
// preserve selected values in the
form, so on error don't lose them
all. preserveSelectedValues(request);
return errs; } // end
of validate
|