@ tefigel |-- | Common template for different Actions. Reuse common code blocks | and differentiate where needed. Fairly complex script. |-- interface(TARGET_ACTION) set CUR_ACTION=~to_lower(TARGET_ACTION) set LOG_MSG=JAVA_CLASS could not be CUR_ACTION&d. set LOG_MSG_TAIL= case TARGET_ACTION when=Create set JLIST=JAVA_PROPERTIES set JIDS=JAVA_PROP_ID_LIST set JCOMMENT= when=Delete set JLIST=JAVA_PKEYS set JIDS=JAVA_PKEY_ID set JCOMMENT= current when=Detail set JLIST= set JIDS= set JCOMMENT= set LOG_MSG=JAVA_CLASS could not be listed. id= set LOG_MSG_TAIL= + index; when=List set JLIST= set JIDS= set JCOMMENT= set LOG_MSG=JAVA_CLASS&s could not be CUR_ACTION&ed when=Update set JLIST=JAVA_PROPERTIES set JIDS=JAVA_PROP_ID_LIST set JCOMMENT= current endcase @ text package JAVA_PACKAGE; @ if TARGET_ACTION=List import java.util.ArrayList; import java.util.Collection; @ endif import javax.servlet.http.*; import org.apache.log4j.Logger; import org.apache.struts.action.*; public final class TARGET_ACTION&JAVA_CLASS&Action extends Common&JAVA_CLASS&Action { private static Logger logger = Logger.getLogger(TARGET_ACTION&JAVA_CLASS&Action.class.getName()); public ActionForward commonExecute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ActionErrors errors = new ActionErrors(); @ case TARGET_ACTION @ when=List // Get the JAVA_CLASS manager factory @ when=Detail // Get the index of the JAVA_CLASS (given in the hyperlink) Detail&JAVA_CLASS&Form df = (Detail&JAVA_CLASS&Form) form; String index = df.get&JAVA_PKEY_UCID(); 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 @ otherwise // Get the data from the Form bean Detail&JAVA_CLASS&Form df = (Detail&JAVA_CLASS&Form) form; @ @ list_process(JLIST,java/action_get) @ // Get the factory class @ endcase HttpSession session = request.getSession(); JAVA_CLASS&ManagerFactoryIF factory = (JAVA_CLASS&ManagerFactoryIF) session.getAttribute("JAVA_OBJ_INSTANCE&factory"); JAVA_CLASS&ManagerIF manager = factory.create&JAVA_CLASS&Manager(); @ case TARGET_ACTION @ when=Create // *************** SHOW REAL ERROR HANDLING: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @ when=Detail // Transfer the data from the JAVA_OBJ_INSTANCE bean to the ActionForm JAVA_CLASS JAVA_OBJ_INSTANCE = null; @ when=List Collection c = new ArrayList(); @ endcase try { @ case TARGET_ACTION @ when=List c = manager.getAll(); @ when=Detail JAVA_OBJ_INSTANCE = manager.get&JAVA_CLASS(index); @ otherwise // TARGET_ACTION the&JCOMMENT JAVA_CLASS manager.CUR_ACTION&JAVA_CLASS(JIDS); @ endcase } catch (DAOException e) { @ if TARGET_ACTION#List // Logging the error: String message = "LOG_MSG"LOG_MSG_TAIL @ @ list_process(JLIST,java/to_string) @ logger.fatal(message, e); @ endif // Message for the user: errors.add("label", new ActionError("error.CUR_ACTION&failed")); saveErrors(request, errors); @ if TARGET_ACTION=List // Logging the error: String message = "LOG_MSG"; logger.fatal(message, e); @ endif // Save the chained exceptions: request.setAttribute("MYEXCEPTION", new DAOException(message, e)); // Return to the error page return (mapping.findForward("error")); } @ case TARGET_ACTION @ when=List session.setAttribute("JAVA_LIST_INSTANCE", c); return (mapping.findForward("list")); @ when=Detail if (JAVA_OBJ_INSTANCE == null) { // Logging the error: String message = "JAVA_CLASS 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")); } @ java/update_properties(action_detail) // Forward control to the list page return (mapping.findForward("detail")); @ otherwise // Forward control to the next page return (mapping.findForward("OK")); @ endcase } }