Skip to content

Instantly share code, notes, and snippets.

@1206yaya
Created January 18, 2015 02:26
Show Gist options
  • Save 1206yaya/61b9db96340f5b339f8e to your computer and use it in GitHub Desktop.
Save 1206yaya/61b9db96340f5b339f8e to your computer and use it in GitHub Desktop.
play tettei 3.3 scalaを使ったテンプレートの記述 @Repeaat
package controllers;
import models.*;
import java.util.*;
import play.*;
import play.data.*;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
// フォーム管理用クラス
public static class SampleForm {
public List<String> inputs;
}
// ルートにアクセスした際のAction
public static Result index() {
Form<SampleForm> form = new Form(SampleForm.class);
return ok(index.render("please set form.", form));
}
// POST送信された際のAction
public static Result send() {
Form<SampleForm> f = new Form(SampleForm.class).bindFromRequest();
if (!f.hasErrors()) {
SampleForm sf = f.get();
String res = "value: ";
for (String s : sf.inputs) {
res += " " + s;
}
sf.inputs.add("");
return ok(index.render(res, f));
} else {
return badRequest(index.render("ERROR", f));
}
}
}
@(msg: String, form1: Form[Application.SampleForm])
@main("Sample Page") {
<h1>Hello!</h1> <p>@msg</p>
@helper.form(action = routes.Application.send) {
@helper.repeat(
field = form1("inputs"), min = 3
) { fld => @helper.inputText(
field = fld, '_label -> "input")
}
<input type="submit">
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment