|
MyEclipse 下开发JSF教程(4)
Furthermore you have to add a constrUCtor, which set the properties if you initialisize the instance variable of the newly object. The following source code show the class book. public class Book implements Serializable {
//------------------ Properties-------------------------------- private long id; private String author; private String title; private boolean available;
//------------------ ConstrUCtors-------------------------------- public Book(){} public Book(long id, String author, String title, boolean available){ this.id = id; this.author = author; this.title = title; this.available = available; }
//------------------ Getter and setter methods ---------------------
public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public boolean isAvailable() { return available; } public void setAvailable(boolean available) { this.available = available; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
Add a getter and setter for the class. /** * Set the properties * @param book */ public void setBook(Book book){ this.setId(book.getId()); this.setAuthor(book.getAuthor()); this.setTitle(book.getTitle()); this.setAvailable(book.isAvailable()); }
/** * @return book object */ public Book getBook(){
return new Book(this.getId(), this.getAuthor(), this.getTitle(), this.isAvailable()); }
The database classWe use a class to provide some test data without using a database. Download the sample application of this tutorial and copy the class SimulateDB.Java find in the folder src/de/laliluna/tutorial/library/ in the package de.laliluna.tutorial.library. The class BookListCreate a futher class BookList in the package de.laliluna.library. This class inlcudes the property books, which represent the list of books. Generate a getter- and seter-method for the property books and change the getter-method like the following. public class BookList {
|