public ActionForward store( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, SessionAPI session) throws Exception { // Comprobar si el usuario tiene asignadas las funciones adecuadas FunctionHelper.checkFunctions( request, session.getClientContext(), new int[] {ISecurityAPI.FUNC_COMP_CALENDARS_EDIT}); ClientContext cct = session.getClientContext(); IInvesflowAPI invesFlowAPI = session.getAPI(); ICatalogAPI catalogAPI = invesFlowAPI.getCatalogAPI(); // Formulario asociado a la acción CalendarForm defaultForm = (CalendarForm) form; // int keyId = Integer.parseInt(defaultForm.getKey()); // int entityId = Integer.parseInt(defaultForm.getEntity()); String parameter = request.getParameter("entityId"); if (parameter == null) { parameter = defaultForm.getEntity(); } int entityId = Integer.parseInt(parameter); parameter = request.getParameter("regId"); int condicion = Integer.parseInt(parameter); if (parameter == null) { parameter = defaultForm.getKey(); } int keyId = Integer.parseInt(parameter); EntityApp entityapp = null; String path = getRealPath(""); // Ejecución en un contexto transaccional boolean bCommit = false; try { // Abrir transacción cct.beginTX(); // Obtener la aplicación que gestiona la entidad if (keyId == ISPACEntities.ENTITY_NULLREGKEYID) { entityapp = catalogAPI.newCTDefaultEntityApp(entityId, path); keyId = entityapp.getEntityRegId(); } else { entityapp = catalogAPI.getCTDefaultEntityApp(entityId, path); } // Permite modificar los datos del formulario defaultForm.setReadonly("false"); // Salva el identificador de la entidad defaultForm.setEntity(Integer.toString(entityId)); // Salva el identificador del registro defaultForm.setKey(Integer.toString(keyId)); defaultForm.processEntityApp(entityapp); // Se le asigna la clave del registro. Es necesario ya que el // item al que hace referencia puede estar recien creado y por tanto // tendría su campo clave a -1 (ISPACEntities.ENTITY_REGKEYID) entityapp.getItem().setKey(keyId); // entityapp.setAppName("EditCalendar"); if (!entityapp.validate()) { ActionMessages errors = new ActionMessages(); List errorList = entityapp.getErrors(); Iterator iteError = errorList.iterator(); while (iteError.hasNext()) { ValidationError validError = (ValidationError) iteError.next(); ActionMessage error = new ActionMessage(validError.getErrorKey(), validError.getArgs()); errors.add("property(NOMBRE)", error); } saveErrors(request, errors); return new ActionForward(mapping.getInput()); } // Guardar la entidad entityapp.store(); // Si todo ha sido correcto se hace commit de la transacción bCommit = true; } catch (ISPACException e) { if (entityapp != null) { // Establecer la aplicación para acceder a los valores extra en // el formulario defaultForm.setValuesExtra(entityapp); // Página jsp asociada a la presentación de la entidad request.setAttribute("application", entityapp.getURL()); request.setAttribute("EntityId", Integer.toString(entityId)); request.setAttribute("KeyId", Integer.toString(keyId)); throw new ISPACInfo(e.getMessage()); } else { // Suele producirse error en las secuencias al estar mal // inicializadas // provocando una duplicación de keys throw e; } } finally { cct.endTX(bCommit); } if (condicion == ISPACEntities.ENTITY_NULLREGKEYID) { return getActionForwardShow(String.valueOf(entityId), String.valueOf(keyId)); } return updateWeekEnd(mapping, defaultForm, request, response, session); // ActionForward forward = mapping.findForward("ShowEntity" + entityId); // if (forward == null) { // // forward = mapping.findForward("reloadShowEntity" + entityId); // if (forward == null) { // forward = mapping.findForward("reload"); // } // // String redirected = forward.getPath() + "?entityId=" + entityId + "®Id=" + keyId; // if (request.getQueryString() != null) { // redirected += "&" + request.getQueryString(); // } // forward = new ActionForward(forward.getName(), redirected, true); // } // // return forward; }