users
[Top] [All Lists]

RE: [cinjug-users] newbie trying to learn m-v-c

To: users@xxxxxxxxxx
Subject: RE: [cinjug-users] newbie trying to learn m-v-c
From: sdgesa gaeharth <pollux1234567890@xxxxxxxxx>
Date: Thu, 9 Sep 2004 08:54:16 -0700 (PDT)
Cc: james@xxxxxxxxxxxxxxxxxxxx
Delivered-to: mailing list users@cinjug.org
In-reply-to: <000a01c49679$a372de80$d040058f@carmani600m>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Well I think I got it!! Thanks for the support. Here
is my final servlet. One last question...Is there
anything I can do to improve this app(besides using a
framework). Is it considered "thread-safe" and
efficient? Or Should these lines(
this.firstName=firstName;) be in the
MemberValidateForm() method instead of the validate
method?

thanks again

package com.bdi.www.members;

import java.util.*;

public class MemberValidateForm {

  private String firstName;
  private String lastName;
  private String emailAddress;
  private String homePhone;
  private Map errors;

  public boolean validate(String firstName,String
lastName,String emailAddress,String homePhone) {
  
        this.firstName=firstName;
        this.lastName=lastName;
        this.emailAddress=emailAddress;
        this.homePhone=homePhone;
    boolean allOk=true;

    if (firstName.equals("")) {
      errors.put("firstName","Please enter your first
name");
      firstName="";
      allOk=false;
    }
    if (lastName.equals("")) {
      errors.put("lastName","Please enter your last
name");
      lastName="";
      allOk=false;
    }
    if (emailAddress.equals("") ||
(emailAddress.indexOf('@') == -1)) {
      errors.put("emailAddress","Please enter a valid
email address");
      emailAddress="";
      allOk=false;
    }
    if (homePhone.equals("")) {
      errors.put("homePhone","Please enter your phone
number");
      homePhone="";
      allOk=false;
    }
    return allOk;
  }

  public MemberValidateForm() {
    firstName="";
    lastName="";
    emailAddress="";
        homePhone="";
        errors = new HashMap();
  }

  public String getFirstName() {
    return firstName;
  }

  public String getLastName() {
    return lastName;
  }

  public String getEmailAddress() {
    return emailAddress;
  }

  public String getHomePhone() {
    return homePhone;
  }

  public void setFirstName(String firstName) {
    this.firstName =firstName;
  }

  public void setLastName(String lastName) {
    this.lastName =lastName;
  }

  public void setEmailAddress(String emailAddress) {
    this.emailAddress=emailAddress;
  }

  public void setHomePhone(String homePhone) {
    this.homePhone=homePhone;
  }

  public Map getErrors() {
    return errors;
  }

}


                
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

<Prev in Thread] Current Thread [Next in Thread>