You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Barnett, Brian W." <bb...@scholarinc.com> on 2004/04/15 17:52:22 UTC

dealing with nullable db columns

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

 

 


Re: dealing with nullable db columns

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Personally, I think you are better off providing a flat ActionForm that 
has String getters/setters for the values from the DTO. This way you can 
do the massaging as you need to/from the view and the DTO can use the 
correct types.  You could put the -999 handling in a utility method.

Barnett, Brian W. wrote:

> 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
> 
>  
> 
>  
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org