Search in sources :

Example 6 with DynamicEntityFormInfo

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;
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) StructuredContentType(org.broadleafcommerce.cms.structure.domain.StructuredContentType) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with DynamicEntityFormInfo

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());
    }
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) HashMap(java.util.HashMap) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)

Aggregations

DynamicEntityFormInfo (org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)7 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Page (org.broadleafcommerce.cms.page.domain.Page)2 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)2 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PageTemplate (org.broadleafcommerce.cms.page.domain.PageTemplate)1 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)1 StructuredContentType (org.broadleafcommerce.cms.structure.domain.StructuredContentType)1