Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Configuration File: application.conf</strong></p> <pre><code>db.default.driver=org.h2.Driver db.default.url="jdbc:h2:mem:play" ebean.default="models.*" </code></pre> <p><strong>Controller Class => Application.java</strong></p> <pre><code>package controllers; import play.*; import play.mvc.*; import models.City; import play.data.Form; import views.html.*; public class Application extends Controller { final static Form&lt;City&gt; cityForm = form(City.class); public static Result index() { City pune=new City(); pune.name="pune"; pune.save(); City mumbai=new City(); mumbai.name="mumbai"; mumbai.save(); City city=City.get(2L); return ok(index.render(cityForm.fill(city),City.all())); } } </code></pre> <p><strong>Model Class => City.java:</strong></p> <pre><code>package models; import javax.persistence.Entity; import javax.persistence.Id; import play.db.ebean.Model; import java.util.List; import com.avaje.ebean.validation.NotNull; @Entity public class City extends Model{ @Id public Long id; @NotNull public String name; public static Finder&lt;Long, City&gt; find = new Finder(Long.class, City.class); public static City get(Long id){ return find.byId(id); } public static List&lt;City&gt; all() { return find.all(); } } </code></pre> <p><strong>Template File => index.scala.html</strong></p> <pre><code>@(cityForm: Form[City],cities: List[City]) &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;select&gt; @for(city &lt;- cities){ &lt;option value="@city.id" @{if(city.id.toString().equals(cityForm("id").value)) "selected='selected'"}/&gt;@city.name&lt;/option&gt; } &lt;/select&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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