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

Reply via email to