id = new Integer(- 1);
}
String persistentsId = FormTools.createContextKey(contextId, id);
FormularDescriptor formular = (FormularDescriptor) UserTools
.getContextObject(wrappedRequest, persistentsId);
if (formular == null)
{
response.setForward("aktera.formular.save-without-edit");
return;
}
SaveFormContext context = new SaveFormContext();
context.setRequest(wrappedRequest);
context.setPersistents(formular.getPersistents());
boolean modified = false;
handler.adjustFormular(wrappedRequest, formular, formular.getPersistents());
if (request.getParameter(NO_FORM_STORE) == null
&& ! NumberTools.toBool(request.getParameter(SYSTEM_EDIT), false))
{
try
{
modified = FormTools.storeInput(wrappedRequest, wrappedResponse, formular, formular
.getPersistents(), logger);
}
catch (Exception x)
{
System.out.println("[Save] Error while storing input: " + x);
x.printStackTrace();
}
}
if (request.getParameter("AKTERA_page") != null)
{
int page = NumberTools.toInt(request.getParameter("AKTERA_page"), formular.getPage());
if (page >= 0)
{
formular.setPage(page);
}
}
if (NumberTools.toBool(request.getParameter("AKTERA_auto"), false))
{
String bean = cmdPage != null && cmdPage.getModel() != null ? cmdPage.getModel() : cmdEdit.getModel();
BeanRequest newRequest = new BeanRequest();
newRequest.setBean(bean);
newRequest.setLocale(request.getLocale());
newRequest.setUserEnvironment(request.getUserEnvironment());
for (Iterator i = request.getParameters().keySet().iterator(); i.hasNext();)
{
String key = (String) i.next();
if (! "model".equals(key) && ! "SEQUENCE_NAME".equals(key) && ! "SEQUENCE_NUMBER".equals(key))
{
newRequest.setParameter(key, request.getParameters().get(key));
}
}
newRequest.setParameter(keyName, id);
newRequest.setParameter("reedit", "Y");
if (request.getParameter("ajax") != null)
{
newRequest.setParameter("ajax", "Y");
}
redirect(bean, newRequest, response);
return;
}
handler.preStorePersistents(wrappedRequest, formular, formular.getPersistents(), new Boolean(modified));
if (request.getParameter(NO_FORM_STORE) == null && validate
&& ! NumberTools.toBool(request.getParameter(SYSTEM_EDIT), false))
{
ValidationResult result = null;
try
{
result = FormTools.validateInput(wrappedRequest, wrappedResponse, formular, formular
.getPersistents());
handler.validatePersistents(persistentConfig, wrappedRequest, wrappedResponse, formular, formular
.getPersistents(), NumberTools.toInt(id, - 1) == - 1, result);
}
catch (Exception x)
{
System.out.println("[Save] Error while validating input: " + x);
x.printStackTrace();
}
if (result.hasErrors())
{
formular.setPage(Math.max(formular.getPageWithField(result.getFirstErrorField(formular).replaceAll(
"_", ".")), 0));
}
result.createResponseElements(wrappedResponse, formular);
if (result.hasErrors())
{
if (! NumberTools.toBool(request.getParameter(SYSTEM_EDIT), false))
{
BeanRequest newRequest = new BeanRequest();
newRequest.setBean(cmdEdit.getModel());
newRequest.setLocale(request.getLocale());
newRequest.setUserEnvironment(request.getUserEnvironment());
newRequest.setParameter(keyName, id);
newRequest.setParameter("error", result.getFirstErrorField(formular));
redirect(cmdEdit.getModel(), newRequest, response);
return;
}
else
{
return;
}
}
}
if (NumberTools.toInt(id, - 1) != - 1)
{
try
{
handler.updatePersistents(wrappedRequest, formular, formular.getPersistents(), persistentConfig,
modified);
}
catch (Exception x)
{
logger.error("Unable to update persistents: " + x);
throw new ModelException(x);
}
if (! preserveContext)
{
UserTools.removeContextObject(wrappedRequest, persistentsId);
}
}
else
{
id = new Integer(handler.createPersistents(wrappedRequest, formular, formular.getPersistents(),
persistentConfig));
if (NumberTools.toInt(id, - 1) != - 1)
{
if (! preserveContext)