Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This code will save your file into a "data/attachments" directory of your project:</p> <h2>Model</h2> <pre><code>package models; import play.db.jpa.Blob; import play.db.jpa.Model; import javax.persistence.Entity; @Entity public class MyApp extends Model { public String name; public Blob file; } </code></pre> <h2>Template</h2> <pre><code>#{form action:@create(), enctype:'multipart/form-data'} #{crud.form /} &lt;label for="uploadFile"&gt;File&lt;/label&gt; &lt;input type="file" id="uploadFile" name="myapp.file" /&gt; &lt;p class="crudButtons"&gt; &lt;input type="submit" name="_save" value="&amp;{'crud.save', type.modelName}" /&gt; &lt;input type="submit" name="_saveAndContinue" value="&amp;{'crud.saveAndContinue', type.modelName}" /&gt; &lt;/p&gt; #{/form} </code></pre> <h2>Controller</h2> <pre><code>package controllers import play.*; import play.mvc.*; import java.util.*; import models.*; /* Custom controller that extends * controller from CRUD module. */ public class MyController extends CRUD { // ... // Will save your object public static void create(MyApp object) { /* Get the current type of controller and test it on non-empty */ ObjectType type = ObjectType.get(getControllerClass()); notFoundIfNull(type); /* We perform validation of the generated crud module form fields */ validation.valid(object); if (validation.hasErrors()) { renderArgs.put("error", Messages.get("crud.hasErrors")); try { render(request.controller.replace(".", "/") + "/blank.html", type, object); } catch (TemplateNotFoundException e) { render("CRUD/blank.html", type, object); } } /* Save our object into db */ object._save(); /* Show messages */ flash.success(Messages.get("crud.created", type.modelName)); if (params.get("_save") != null) { redirect(request.controller + ".list"); } if (params.get("_saveAndAddAnother") != null) { redirect(request.controller + ".blank"); } } </code></pre> <p>As stated above, you simply complements crud form by your own field and overrides crud method "create". The same can be done to update the record. You can change "data/attachments" directory in your application.conf:</p> <h2>application.conf</h2> <pre><code># ... # Store path for Blob content attachments.path=data/attachments # ... </code></pre> <p>For more details see <a href="http://www.lunatech-research.com/playframework-file-upload-blob" rel="nofollow">http://www.lunatech-research.com/playframework-file-upload-blob</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload