public EditStudentPage(WOContext context) {
   super(context);
   // Add new Student to editing context
   student = new Student();
   homeAddress = new HomeAddress();
   student.setAddress(homeAddress);
   session().defaultEditingContext().insertObject(student);
   session().defaultEditingContext().insertObject(homeAddress);
 }
  private void init() {
    String name = "manikanta";
    for (int i = 5; i >= 0; i--, initid++) {
      Student s = new Student();
      s.setId(initid);
      s.setName(name.substring(0, i + 4));
      s.setContact(98988989);
      Address ad = new Address();

      s.setAddress(ad);
      Students.put(initid, s);
    }

    // Student s=new Student();
    // s.setId(initid);
    // s.setName("Mani");
    // Students.put(s.getId(), s);
  }
  /** Save changes to database */
  public WOComponent saveChanges() {

    Session session = (Session) session();
    EOEditingContext context = session.defaultEditingContext();
    String msg = null;
    ErrorPage errorPage = (ErrorPage) pageWithName("ErrorPage");

    // Verify student's first name
    msg = session.isValidName(student.firstName());
    if (msg != null) {
      errorPage.setErrorMsg(msg);
      errorPage.setNextPage(this);
      return (errorPage);
    }

    // Verify student's last name
    msg = session.isValidName(student.lastName());
    if (msg != null) {
      errorPage.setErrorMsg(msg);
      errorPage.setNextPage(this);
      return (errorPage);
    }

    // Verify student's date of birth
    if (student.dateOfBirth() != null || error != null) {
      error = null;
      msg = session.isValidDate(student.dateOfBirth());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's street
    if (homeAddress.street() != null) {
      msg = session.isValidStreet(homeAddress.street());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's city
    if (homeAddress.city() != null) {
      if (homeAddress.city() != null) {
        msg = session.isValidCity(homeAddress.city());
        if (msg != null) {
          errorPage.setErrorMsg(msg);
          errorPage.setNextPage(this);
          return (errorPage);
        }
      }
    }

    // Verify student's state
    if (homeAddress.state() != null) {
      msg = session.isValidState(homeAddress.state());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's ZIP code
    if (homeAddress.zip() != null) {
      msg = session.isValidZip(homeAddress.zip());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's email address
    if (homeAddress.emailAddress() != null) {
      msg = session.isValidEmail(homeAddress.emailAddress());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's login
    msg = session.isValidLogin(student.login());
    if (msg != null) {
      errorPage.setErrorMsg(msg);
      errorPage.setNextPage(this);
      return (errorPage);
    }
    // Verify student's password
    msg = session.isValidPassword(student.password());
    if (msg != null) {
      errorPage.setErrorMsg(msg);
      errorPage.setNextPage(this);
      return (errorPage);
    }

    // Save changes in database
    if (student.firstName() != null && student.lastName() != null) {
      // save changes permanently in database
      context.saveChanges();
    }

    // Add new Student to editing context
    student = new Student();
    homeAddress = new HomeAddress();
    student.setAddress(homeAddress);
    session.defaultEditingContext().insertObject(student);
    session.defaultEditingContext().insertObject(homeAddress);
    return null;
  }