package dk.hansen; import javax.servlet.http.*; import org.apache.log4j.Logger; import org.apache.struts.action.*; public final class DetailVhsAction extends CommonVhsAction { private static Logger logger = Logger.getLogger(DetailVhsAction.class.getName()); public ActionForward commonExecute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ActionErrors errors = new ActionErrors(); // Get the index of the Vhs (given in the hyperlink) DetailVhsForm df = (DetailVhsForm) form; String index = df.getId(); if (index == null || index.equals("")) { // Logging the error: String message = "No id given to the detail action"; logger.fatal(message); // Message for the user: errors.add("label", new ActionError("error.noindex")); saveErrors(request, errors); // Save the exception: request.setAttribute("MYEXCEPTION", new DAOException(message)); // Return to the error page return (mapping.findForward("error")); } // Get the factory class HttpSession session = request.getSession(); VhsManagerFactoryIF factory = (VhsManagerFactoryIF) session.getAttribute("vhsfactory"); VhsManagerIF manager = factory.createVhsManager(); // Transfer the data from the vhs bean to the ActionForm Vhs vhs = null; try { vhs = manager.getVhs(index); } catch (DAOException e) { // Logging the error: String message = "Vhs could not be listed. id=" + index; logger.fatal(message, e); // Message for the user: errors.add("label", new ActionError("error.detailfailed")); saveErrors(request, errors); // Save the chained exceptions: request.setAttribute("MYEXCEPTION", new DAOException(message, e)); // Return to the error page return (mapping.findForward("error")); } if (vhs == null) { // Logging the error: String message = "Vhs could not be listed. id=" + index; logger.fatal(message); // Message for the user: errors.add("label", new ActionError("error.detailfailed")); saveErrors(request, errors); // Save the chained exceptions: request.setAttribute("MYEXCEPTION", new DAOException(message)); // Return to the error page return (mapping.findForward("error")); } df.setYear(vhs.getYear()); df.setTitle(vhs.getTitle()); df.setTapeLength(vhs.getTapeLength()); // Forward control to the list page return (mapping.findForward("detail")); } }