use of org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo in project BroadleafCommerce by BroadleafCommerce.
the class AdminStructuredContentController 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");
// Attach the dynamic fields to the form
DynamicEntityFormInfo info = new DynamicEntityFormInfo().withCeilingClassName(StructuredContentType.class.getName()).withSecurityCeilingClassName(StructuredContent.class.getName()).withCriteriaName("constructForm").withPropertyName("structuredContentType").withPropertyValue(ef.findField("structuredContentType").getValue());
EntityForm dynamicForm = getDynamicFieldTemplateForm(info, id, null);
ef.putDynamicFormInfo("structuredContentType", info);
ef.putDynamicForm("structuredContentType", dynamicForm);
// We don't want to allow changing types once a structured content item exists
ef.findField("structuredContentType").setReadOnly(true);
return returnPath;
}
use of org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method extractDynamicFormFields.
/**
* This method will scan the entityForm for all dynamic form fields and pull them out
* as appropriate.
*
* @param cmd
* @param entityForm
*/
protected void extractDynamicFormFields(ClassMetadata cmd, EntityForm entityForm) {
Map<String, Field> dynamicFields = new HashMap<>();
// Find all of the dynamic form fields
for (Entry<String, Field> entry : entityForm.getFields().entrySet()) {
if (entry.getKey().contains(DynamicEntityFormInfo.FIELD_SEPARATOR)) {
dynamicFields.put(entry.getKey(), entry.getValue());
}
}
// Remove the dynamic form fields from the main entity - they are persisted separately
for (Entry<String, Field> entry : dynamicFields.entrySet()) {
entityForm.removeField(entry.getKey());
}
// Create the entity form for the dynamic form, as it needs to be persisted separately
for (Entry<String, Field> entry : dynamicFields.entrySet()) {
String[] fieldName = entry.getKey().split("\\" + DynamicEntityFormInfo.FIELD_SEPARATOR);
DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(fieldName[0]);
EntityForm dynamicForm = entityForm.getDynamicForm(fieldName[0]);
if (dynamicForm == null) {
dynamicForm = new EntityForm();
dynamicForm.setCeilingEntityClassname(info.getCeilingClassName());
entityForm.putDynamicForm(fieldName[0], dynamicForm);
}
entry.getValue().setName(fieldName[1]);
dynamicForm.addField(cmd, entry.getValue());
}
}
Aggregations