/** * Create request mode means that the user requests the application to create a new persistent * bean with supplied information.. In create request mode, new data is stored in persistent * storage. The request should provide data for all properties of the {@link PersistentBean}, * except the {@link PersistentBean#getId()}. If the create operation succeeds, the data is simply * displayed in a non-editable way. If the create operation fails, the data is displayed in an * HTML form, so that it can be corrected. * * @pre form != null; * @pre form.getPersistentBean() != null; * @pre request != null; */ private void templateCreate(final CrudDynaActionForm form, final HttpServletRequest request) throws CompoundPropertyException, TechnicalException { assert form != null; assert request != null; if (LOG.isDebugEnabled()) { LOG.debug("create action ..."); // $NON-NLS-1$ } form.initBean(); /* * BeanInstantiationException; this means that the app is wrongly * configured; this will generate a general error page. */ assert form.getPersistentBean() != null; assert form.getPersistentBean().getId() == null; form.setViewModeDeleted(false); AsynchronousCRUD asyncCRUD = createAsynchronousCRUD(request); try { asyncCRUD.startTransaction(); form.formToBean(asyncCRUD); // PropertyException, inside transaction form.getPersistentBean().setId(null); asyncCRUD.createPersistentBean(form.getPersistentBean()); // PropertyException form.beanToId(); form.beanToForm(asyncCRUD); // inside transaction asyncCRUD.commitTransaction(form.getPersistentBean()); form.setViewModeEdit(false); CreatedEvent pbnEvent = new CreatedEvent(form.getPersistentBean()); fireCommittedEvent(pbnEvent); assert !form.isViewModeNew(); assert !form.isViewModeDeleted(); if (LOG.isDebugEnabled()) { LOG.debug("create action succeeded"); // $NON-NLS-1$ } } catch (CompoundPropertyException cpExc) { form.beanToForm(asyncCRUD); asyncCRUD.cancelTransaction(); form.setViewModeNew(true); assert form.isViewModeEdit(); assert !form.isViewModeDeleted(); throw cpExc; } finally { releaseAsynchronousCRUD(asyncCRUD); } }