package dk.hansen; import javax.servlet.http.*; import org.apache.log4j.Logger; import org.apache.struts.action.*; public final class UpdateVhsAction extends CommonVhsAction { private static Logger logger = Logger.getLogger(UpdateVhsAction.class.getName()); public ActionForward commonExecute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ActionErrors errors = new ActionErrors(); // Get the data from the Form bean DetailVhsForm df = (DetailVhsForm) form; String id = df.getId(); int year = df.getYear(); String title = df.getTitle(); int tapeLength = df.getTapeLength(); // Get the factory class HttpSession session = request.getSession(); VhsManagerFactoryIF factory = (VhsManagerFactoryIF) session.getAttribute("vhsfactory"); VhsManagerIF manager = factory.createVhsManager(); try { // Update the current Vhs manager.updateVhs(id, year, title, tapeLength); } catch (DAOException e) { // Logging the error: String message = "Vhs could not be updated. " + "id=" + id + ", year=" + year + ", title=" + title + ", tapeLength=" + tapeLength; 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")); } }