throw new Http404("Class not found, or not authorized");
} else if (!ma.isAuthor(request.getUser())) {
throw new Http404("Class not found, or not authorized");
}
Manager manager = findManager(pc, ma);
Object object = null;
if (object_id != null) {
object = manager.get(object_id);
if (object == null) {
return new SimpleHttpResponse("Object not found");
}
}
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());
}