package dk.hansen; import javax.servlet.http.*; import org.apache.log4j.Logger; import org.apache.struts.action.*; public final class CreateDVDAction extends CommonDVDAction { private static Logger logger = Logger.getLogger(CreateDVDAction.class.getName()); public ActionForward commonExecute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ActionErrors errors = new ActionErrors(); // Get the data from the Form bean DetailDVDForm df = (DetailDVDForm) form; String id = df.getId(); String title = df.getTitle(); // Get the factory class HttpSession session = request.getSession(); DVDManagerFactoryIF factory = (DVDManagerFactoryIF) session.getAttribute("dvdfactory"); DVDManagerIF manager = factory.createDVDManager(); // *************** SHOW REAL ERROR HANDLING: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! try { // Create the DVD manager.createDVD(id, title); } catch (DAOException e) { // Logging the error: String message = "DVD could not be created. " + "id=" + id + ", title=" + title; logger.fatal(message, e); // Message for the user: errors.add("label", new ActionError("error.createfailed")); 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")); } }