O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The ReportEntry Class

The com.mycompany.expense.ReportEntry class, shown in Example 5-1, is a simple bean, with properties for all expense report entry items—the date, the expense type, and the amount—plus the entry’s ID, unique within a Report.

Example 5-1. The ReportEntry class
package com.mycompany.expense;

import java.io.Serializable;
import java.util.Date;

public class ReportEntry implements Serializable {
    private int id = -1;
    private Date date;
    private int type;
    private double amount;

    public ReportEntry( ) {
    }

    public ReportEntry(ReportEntry src) {
        this.setId(src.getId( ));
        this.setDate(src.getDate( ));
        this.setType(src.getType( ));
        this.setAmount(src.getAmount( ));
    }

    public int getId( ) {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Date getDate( ) {
        if (date == null) {
            date = new Date( );
        }
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public int getType( ) {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public double getAmount( ) {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public String toString( ) {
        return "id: " + id + " date: " + date + " type: " + type + 
            " amount: " + amount;
    }
}

Each property is represented by standard JavaBeans accessor methods: getId() and setId(), getDate() and setDate(), getType() and setType(), and getAmount() and setAmount(). The ReportEntry class also has a copy constructor, i.e., a constructor that initializes the new instance’s properties to the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required