|
MyEclipse 下开发JSF教程(6) * Initial the properties of the class with null * @param event */ public void initBook(ActionEvent event){
/* * init the book object */ this.setBook(new Book()); }
Edit a book/** * Get the book to edit and assign it to the bean * * @param event */ public void selectBook(ActionEvent event){
SimulateDB simulateDB = new SimulateDB();
/* * Get the session map of the external context */ Map session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
/* * Find the UIParameter component by eXPression */ UIParameter component = (UIParameter) event.getComponent().findComponent("editId");
/* * parse the value of the UIParameter component */ long id = Long.parseLong(component.getValue().toString());
/* * get the book by id and set it in the local property */ this.setBook(simulateDB.loadBookById(id, session)); }
Save a book/** * Add or update the book in the simulated database. * If the book id is not set the book will be added * otherwise the book will be updated * * @param event */ public void saveBook(ActionEvent event){
SimulateDB simulateDB = new SimulateDB();
/* * Get the session map of the external context */ Map session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
/* * Add or update the book in the simulated database */ simulateDB.saveToDB(this.getBook(), session); }
Delete a book/** * Delete a book in the simulated database * * @param event */ public void deleteBook(ActionEvent event){
SimulateDB simulateDB = new SimulateDB();
/*
|