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

Implementing the Business Logic Classes

The expense report application contains three business logic classes, shown in Figure 5-2. These classes have no dependencies on JSF (or any other presentation technology, for that matter).

The business logic classes

Figure 5-2. The business logic classes

A Report contains ReportEntry instances, and Report instances are saved in a ReportRegistry, which is an abstract class with concrete subclasses for different storage medias. The FileReportRegistry implements a simple filesystem-based storage facility.

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

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