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

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.