use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.
the class JSFieldNameCompatibilityInterceptor method postHandle.
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
if (modelAndView != null) {
Entity entity = (Entity) modelAndView.getModelMap().get("entity");
EntityForm entityForm = (EntityForm) modelAndView.getModelMap().get("entityForm");
if (entity != null) {
if (entity.getProperties() != null) {
for (Property property : entity.getProperties()) {
if (property.getName().contains(".")) {
property.setName(JSCompatibilityHelper.encode(property.getName()));
}
}
}
}
if (entityForm != null) {
entityForm.clearFieldsMap();
for (Map.Entry<String, Field> field : entityForm.getFields().entrySet()) {
if (field.getKey().contains(".")) {
field.getValue().setName(JSCompatibilityHelper.encode(field.getValue().getName()));
field.getValue().setAssociatedFieldName(JSCompatibilityHelper.encode(field.getValue().getAssociatedFieldName()));
if (field.getValue() instanceof RuleBuilderField) {
((RuleBuilderField) field.getValue()).setJsonFieldName(JSCompatibilityHelper.encode(((RuleBuilderField) field.getValue()).getJsonFieldName()));
}
}
}
entityForm.clearFieldsMap();
}
}
}
use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method getDynamicForm.
/**
* Returns a partial representing a dynamic form. An example of this is the dynamic fields that render
* on structured content, which are determined by the currently selected structured content type. This
* method is typically only invoked through Javascript and used to replace the current dynamic form with
* the one for the newly selected type.
*
* @param request
* @param response
* @param model
* @param pathVars
* @param info
* @return the return view path
* @throws Exception
*/
protected String getDynamicForm(HttpServletRequest request, HttpServletResponse response, Model model, Map<String, String> pathVars, DynamicEntityFormInfo info) throws Exception {
String sectionKey = getSectionKey(pathVars);
EntityForm blankFormContainer = new EntityForm();
EntityForm dynamicForm = getEntityForm(info);
// Set the specialized name for these fields - we need to handle them separately
setSpecializedNameForFields(info, dynamicForm);
blankFormContainer.putDynamicForm(info.getPropertyName(), dynamicForm);
model.addAttribute("dynamicForm", dynamicForm);
model.addAttribute("entityForm", blankFormContainer);
model.addAttribute("dynamicPropertyName", info.getPropertyName());
String reqUrl = request.getRequestURL().toString();
reqUrl = reqUrl.substring(0, reqUrl.indexOf("/dynamicForm"));
model.addAttribute("currentUrl", reqUrl);
setModelAttributes(model, sectionKey);
return "views/dynamicFormPartial";
}
use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm 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