use of org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo in project BroadleafCommerce by BroadleafCommerce.
the class AdminPageController method saveEntity.
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String saveEntity(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {
// Attach the dynamic form info so that the update service will know how to split up the fields
DynamicEntityFormInfo info = new DynamicEntityFormInfo().withCeilingClassName(PageTemplate.class.getName()).withSecurityCeilingClassName(Page.class.getName()).withCriteriaName("constructForm").withPropertyName("pageTemplate");
entityForm.putDynamicFormInfo("pageTemplate", info);
String returnPath = super.saveEntity(request, response, model, pathVars, id, entityForm, result, ra);
if (result.hasErrors()) {
info = entityForm.getDynamicFormInfo("pageTemplate");
if (entityForm.getFields().containsKey("pageTemplate")) {
info.setPropertyValue(entityForm.findField("pageTemplate").getValue());
}
// grab back the dynamic form that was actually put in
EntityForm inputDynamicForm = entityForm.getDynamicForm("pageTemplate");
if (inputDynamicForm != null) {
List<Field> fieldsToChange = new ArrayList<Field>();
String prefix = "pageTemplate" + DynamicEntityFormInfo.FIELD_SEPARATOR;
for (Entry<String, Field> entry : inputDynamicForm.getFields().entrySet()) {
if (entry.getKey().startsWith(prefix)) {
fieldsToChange.add(entry.getValue());
}
}
for (Field f : fieldsToChange) {
inputDynamicForm.getFields().remove(f.getName());
f.setName(f.getName().substring(prefix.length()));
inputDynamicForm.getFields().put(f.getName(), f);
}
}
EntityForm dynamicForm;
if (info.getPropertyValue() != null) {
dynamicForm = getDynamicFieldTemplateForm(info, id, inputDynamicForm);
} else {
dynamicForm = getEntityForm(info, inputDynamicForm);
}
entityForm.putDynamicForm("pageTemplate", dynamicForm);
entityForm.removeListGrid("additionalAttributes");
}
return returnPath;
}
use of org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo in project BroadleafCommerce by BroadleafCommerce.
the class AdminStructuredContentController method saveEntity.
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String saveEntity(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {
// Attach the dynamic form info so that the update service will know how to split up the fields
DynamicEntityFormInfo info = new DynamicEntityFormInfo().withCeilingClassName(StructuredContentType.class.getName()).withSecurityCeilingClassName(StructuredContent.class.getName()).withCriteriaName("constructForm").withPropertyName("structuredContentType");
entityForm.putDynamicFormInfo("structuredContentType", info);
String returnPath = super.saveEntity(request, response, model, pathVars, id, entityForm, result, ra);
if (result.hasErrors()) {
info = entityForm.getDynamicFormInfo("structuredContentType");
info.setPropertyValue(entityForm.findField("structuredContentType").getValue());
// grab back the dynamic form that was actually put in
EntityForm inputDynamicForm = entityForm.getDynamicForm("structuredContentType");
EntityForm dynamicForm = getDynamicFieldTemplateForm(info, id, inputDynamicForm);
entityForm.putDynamicForm("structuredContentType", dynamicForm);
}
return returnPath;
}
use of org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method addEntity.
@Override
public PersistenceResponse addEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException {
PersistencePackageRequest ppr = getRequestForEntityForm(entityForm, customCriteria, sectionCrumb);
// based on the criteria specific in the PersistencePackage.
for (Entry<String, EntityForm> entry : entityForm.getDynamicForms().entrySet()) {
DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(entry.getKey());
if (info.getCustomCriteriaOverride() != null) {
customCriteria = info.getCustomCriteriaOverride();
} else {
String propertyName = info.getPropertyName();
String propertyValue;
if (entityForm.getFields().containsKey(propertyName)) {
propertyValue = entityForm.findField(propertyName).getValue();
} else {
propertyValue = info.getPropertyValue();
}
customCriteria = new String[] { info.getCriteriaName(), entityForm.getId(), propertyName, propertyValue };
}
PersistencePackageRequest subRequest = getRequestForEntityForm(entry.getValue(), customCriteria, sectionCrumb);
ppr.addSubRequest(info.getPropertyName(), subRequest);
}
return add(ppr);
}
use of org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method updateEntity.
@Override
public PersistenceResponse updateEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException {
PersistencePackageRequest ppr = getRequestForEntityForm(entityForm, customCriteria, sectionCrumb);
ppr.setRequestingEntityName(entityForm.getMainEntityName());
// based on the criteria specific in the PersistencePackage.
for (Entry<String, EntityForm> entry : entityForm.getDynamicForms().entrySet()) {
DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(entry.getKey());
if (info.getCustomCriteriaOverride() != null) {
customCriteria = info.getCustomCriteriaOverride();
} else {
String propertyName = info.getPropertyName();
String propertyValue = entityForm.findField(propertyName).getValue();
customCriteria = new String[] { info.getCriteriaName(), entityForm.getId(), propertyName, propertyValue };
}
PersistencePackageRequest subRequest = getRequestForEntityForm(entry.getValue(), customCriteria, sectionCrumb);
subRequest.withSecurityCeilingEntityClassname(info.getSecurityCeilingClassName());
ppr.addSubRequest(info.getPropertyName(), subRequest);
}
return update(ppr);
}
use of org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo in project BroadleafCommerce by BroadleafCommerce.
the class AdminPageController method viewEntityForm.
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String viewEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id) throws Exception {
// Get the normal entity form for this item
String returnPath = super.viewEntityForm(request, response, model, pathVars, id);
EntityForm ef = (EntityForm) model.asMap().get("entityForm");
DynamicEntityFormInfo info = getDynamicForm(ef, id);
EntityForm dynamicForm;
if (info.getPropertyValue() != null) {
dynamicForm = getDynamicFieldTemplateForm(info, id, null);
} else {
dynamicForm = getEntityForm(info, null);
}
if (dynamicForm.getCeilingEntityClassname().equals(PageTemplate.class.getName())) {
dynamicForm.setTranslationCeilingEntity(Page.class.getName());
dynamicForm.setTranslationId(id);
}
ef.putDynamicFormInfo("pageTemplate", info);
ef.putDynamicForm("pageTemplate", dynamicForm);
// Mark the field that will drive this dynamic form
addOnChangeTrigger(ef);
ef.removeListGrid("additionalAttributes");
return returnPath;
}
Aggregations