}
}
String[] property_list = ma.getFields();
Form form = ma.getForm();
if (form == null) {
String[] includeFields = property_list == null ? getIncludeFields(pc) : property_list;
ModelForm mForm = new ModelForm(fieldFactory, hibernateUtil, managers);
if (includeFields != null) mForm.setInclude(includeFields);
mForm.setModel(pc);
form = mForm;
}
if ("POST".equals(request.getMethod())) {
// update the object
if (object == null) object=injector.getInstance(pc);
form.bind(request.getParameterMap());
// form = modelFactory.form(pc.getMappedClass(), request.getParameterMap());
if (form.isValid()) {
// if (object_id == null) { // this is a new object
// if (!bl.canCreate()) {
// throw new HttpException("Unable to create");
// }
// } else {
// if (!bl.canUpdate(object)) {
// throw new HttpException("Unable to updte");
// }
// }
form.clean(object);
try {
if (object_id == null) {
manager.create(object);
} else {
manager.save(object);
}
if (request.getParameterMap().containsKey("_addanother")) {
return new HttpResponseRedirect("../add");
} else if (request.getParameterMap().containsKey("_continue")) {
return new HttpResponseRedirect(String.format("../%s/", manager.getPk(object)));
}
return new HttpResponseRedirect("..");
} catch (ManagerException e) {
request.getSession().addError(e.getMessage());
}
}
} else {
// display the form
if (object != null) form.setInitial(object);
}
Map<String, Object> context = new HashMap<String, Object>();
context.put("property_list", property_list);
context.put("object", object);