コード例 #1
0
ファイル: CRUD.java プロジェクト: playframework/play1
 @SuppressWarnings("deprecation")
 public static void attachment(String id, String field) throws Exception {
   ObjectType type = ObjectType.get(getControllerClass());
   notFoundIfNull(type);
   Model object = type.findById(id);
   notFoundIfNull(object);
   Object att = object.getClass().getField(field).get(object);
   if (att instanceof Model.BinaryField) {
     Model.BinaryField attachment = (Model.BinaryField) att;
     if (attachment == null || !attachment.exists()) {
       notFound();
     }
     response.contentType = attachment.type();
     renderBinary(attachment.get(), attachment.length());
   }
   // DEPRECATED
   if (att instanceof play.db.jpa.FileAttachment) {
     play.db.jpa.FileAttachment attachment = (play.db.jpa.FileAttachment) att;
     if (attachment == null || !attachment.exists()) {
       notFound();
     }
     renderBinary(attachment.get(), attachment.filename);
   }
   notFound();
 }
コード例 #2
0
ファイル: CRUD.java プロジェクト: playframework/play1
 public static void show(String id) throws Exception {
   ObjectType type = ObjectType.get(getControllerClass());
   notFoundIfNull(type);
   Model object = type.findById(id);
   notFoundIfNull(object);
   try {
     render(type, object);
   } catch (TemplateNotFoundException e) {
     render("CRUD/show.html", type, object);
   }
 }
コード例 #3
0
ファイル: CRUD.java プロジェクト: playframework/play1
 public static void delete(String id) throws Exception {
   ObjectType type = ObjectType.get(getControllerClass());
   notFoundIfNull(type);
   Model object = type.findById(id);
   notFoundIfNull(object);
   try {
     object._delete();
   } catch (Exception e) {
     flash.error(play.i18n.Messages.get("crud.delete.error", type.modelName));
     redirect(request.controller + ".show", object._key());
   }
   flash.success(play.i18n.Messages.get("crud.deleted", type.modelName));
   redirect(request.controller + ".list");
 }
コード例 #4
0
ファイル: CRUD.java プロジェクト: playframework/play1
 public static void save(String id) throws Exception {
   ObjectType type = ObjectType.get(getControllerClass());
   notFoundIfNull(type);
   Model object = type.findById(id);
   notFoundIfNull(object);
   Binder.bindBean(params.getRootParamNode(), "object", object);
   validation.valid(object);
   if (validation.hasErrors()) {
     renderArgs.put("error", play.i18n.Messages.get("crud.hasErrors"));
     try {
       render(request.controller.replace(".", "/") + "/show.html", type, object);
     } catch (TemplateNotFoundException e) {
       render("CRUD/show.html", type, object);
     }
   }
   object._save();
   flash.success(play.i18n.Messages.get("crud.saved", type.modelName));
   if (params.get("_save") != null) {
     redirect(request.controller + ".list");
   }
   redirect(request.controller + ".show", object._key());
 }