package dk.hansen; import javax.servlet.http.*; import org.apache.log4j.Logger; import org.apache.struts.action.*; public final class UpdateBookAction extends CommonBookAction { private static Logger logger = Logger.getLogger(UpdateBookAction.class.getName()); public ActionForward commonExecute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ActionErrors errors = new ActionErrors(); // Get the data from the Form bean DetailBookForm df = (DetailBookForm) form; String id = df.getId(); String title = df.getTitle(); String author = df.getAuthor(); int year = df.getYear(); // Get the factory class HttpSession session = request.getSession(); BookManagerFactoryIF factory = (BookManagerFactoryIF) session.getAttribute("bookfactory"); BookManagerIF manager = factory.createBookManager(); try { // Update the current Book manager.updateBook(id, title, author, year); } catch (DAOException e) { // Logging the error: String message = "Book could not be updated. " + "id=" + id + ", title=" + title + ", author=" + author + ", year=" + year; logger.fatal(message, e); // Message for the user: errors.add("label", new ActionError("error.updatefailed")); saveErrors(request, errors); // Save the chained exceptions: request.setAttribute("MYEXCEPTION", new DAOException(message, e)); // Return to the error page return (mapping.findForward("error")); } // Forward control to the next page return (mapping.findForward("OK")); } }