Wondering if anybody has a slick way of dealing with nullable database
columns. We have a data transfer object that has member variables, one for
each database column, and of course all the getters and setters.

 

For View layer purposes, we have a class which extends Struts'
ValidatorForm. This Form class has a DTO as a member variable.

 

public class SchoolYearDTO implements Serializable {

  private int yearId;

  private String externalKey;

  private String display;

  private int yearBegin;

  private int yearEnd;

  // getters and setters follow...

}

 

public class SchoolYearForm extends BaseForm {

  private SchoolYearDTO schoolYearDTO;

  // additional view only member variables are included here as well

  public SchoolYearDTO getSchoolYearDTO() {

    return schoolYearDTO;

  }

  public void setSchoolYearDTO(SchoolYearDTO schoolYearDTO) {

    this.schoolYearDTO = schoolYearDTO;

  }

}

 

The jsp pages use the Form like this:

 

<td class="form">

  <html:text name="schoolYearForm" property="schoolYearDTO.externalKey"/>

</td>

 

What we are hoping to avoid is a duplicate set of member variables with
accompanying getters and setters in the Form object for the nullable fields.
(These getters and setters would essentially move data back and forth
between the view and the DTO, "massaging" it as appropriate for the view and
for the database. Is there a better way?)

 

For those familiar with iBatis, we are using the "null" functionality
provided there, but we don't want -999 appearing in the user interface for
null integers, we just want the text box to be empty.

 

Thanks,

Brian Barnett

 

 

Reply via email to