Last active
August 29, 2015 14:13
-
-
Save 1206yaya/05343dd1ea7859dd8c76 to your computer and use it in GitHub Desktop.
play tettei 3.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 String input; | |
public String pass; | |
public boolean check; | |
public String radio; | |
public String sel; | |
public String area; | |
public Date date; | |
} | |
// ルートにアクセスした際のAction | |
public static Result index() { | |
SampleForm sf = new SampleForm(); | |
sf.radio = "windows"; | |
sf.check = true; | |
sf.input = "default value"; | |
sf.sel = "uk"; | |
Form<SampleForm> form = new Form(SampleForm.class).fill(sf); | |
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: "; | |
res += "input=" + sf.input | |
+ ", pass=" + sf.pass | |
+ ", check=" + sf.check + ", radio=" + sf.radio + ", sel=" + sf.sel | |
+ ", area=" + sf.area | |
+ ", date=" + sf.date; | |
return ok(index.render(res, f)); | |
} else { | |
return badRequest(index.render("ERROR", f)); | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@(msg: String, form1: Form[Application.SampleForm]) | |
@main("Sample Page") { | |
<h1>Hello!</h1> <p>@msg</p> | |
@helper.form(action = routes.Application.send){ | |
@(helper.inputText ( | |
field = form1("input"), args = 'size->30 | |
)) @(helper.inputPassword ( | |
field = form1("pass"), | |
args = 'size->30 | |
)) | |
@(helper.checkbox ( | |
field = form1("check") | |
)) | |
@(helper.inputRadioGroup ( | |
field = form1("radio"), | |
options = Seq("windows"->"MS-Windows", | |
"mac"->"Mac OS X","linux"->"Linux") | |
)) | |
@(helper.select ( | |
field = form1("sel"), options = Seq("jp"->"日本", | |
"us"->"米国","uk"->"英国"), args = 'size -> 3 | |
)) | |
@(helper.textarea ( | |
field = form1("area"), | |
args = 'cols -> 30, 'rows -> 3 )) | |
@(helper.inputDate ( field = form1("date") | |
)) | |
<input type="submit"> | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET / controllers.Application.index | |
POST / controllers.Application.send |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@(msg: String, form1: Form[Application.SampleForm]) | |
@main("Sample Page") { | |
<h1>Hello!</h1> <p>@msg</p> | |
@helper.form(action = routes.Application.send) { | |
@(helper.inputText( | |
field = form1("input"), | |
args = '_label -> "Your Name:", '_help -> "名前を書いてください。", 'size -> 30 | |
)) | |
@(helper.inputPassword( | |
field = form1("pass"), | |
args = '_label -> "Password:", '_help -> "パスワードを書いてください。", 'size -> 30 | |
)) | |
<input type="submit"> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment