質問編集履歴
3
内容調整
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,8 +20,6 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
|
24
|
-
|
25
23
|
public String title = "入力画面";
|
26
24
|
|
27
25
|
public String msg = "フォームを入力";
|
@@ -30,24 +28,28 @@
|
|
30
28
|
|
31
29
|
public Result sendform(){
|
32
30
|
|
33
|
-
Form<Sample
|
31
|
+
Form<SampleData> dataform = form(SampleData.class).bindFromRequest();
|
34
32
|
|
35
33
|
if(!dataform.hasErrors()){
|
36
34
|
|
37
|
-
SampleData nitta =
|
35
|
+
SampleData nitta = dataform.get();
|
38
36
|
|
39
37
|
nitta.save();
|
40
38
|
|
41
|
-
flash();
|
39
|
+
flash("success", "きっちり入力できました!!");
|
40
|
+
|
41
|
+
return redirect("/");
|
42
42
|
|
43
43
|
}else {
|
44
44
|
|
45
45
|
flash("error", "入力内容に誤りがあります!!");
|
46
46
|
|
47
|
+
List<SampleData> datas = SampleData.find.all();
|
48
|
+
|
49
|
+
return badRequest(mynum.render(title, msg, datas, dataform));
|
50
|
+
|
47
51
|
}
|
48
52
|
|
49
|
-
return redirect("/");
|
50
|
-
|
51
53
|
}
|
52
54
|
|
53
55
|
}
|
2
内容調整
test
CHANGED
File without changes
|
test
CHANGED
@@ -220,62 +220,42 @@
|
|
220
220
|
|
221
221
|
|
222
222
|
|
223
|
+
public static Finder<Long, SampleData> find =
|
224
|
+
|
225
|
+
new Finder<Long, SampleData>(Long.class, SampleData.class);
|
226
|
+
|
227
|
+
|
228
|
+
|
223
|
-
public SampleData
|
229
|
+
public static SampleData converttoModel(Sampleform sampleform) {
|
224
|
-
|
230
|
+
|
225
|
-
// TODO 自動生成された
|
231
|
+
// TODO 自動生成されたメソッド・スタブ
|
226
|
-
|
232
|
+
|
227
|
-
|
233
|
+
SampleData Sam_data = new SampleData();
|
234
|
+
|
228
|
-
|
235
|
+
Sam_data.id = StringUtils.isNotEmpty(sampleform.id)?Long.valueOf(sampleform.id):null;
|
236
|
+
|
229
|
-
t
|
237
|
+
Sam_data.name = sampleform.name;
|
230
|
-
|
238
|
+
|
231
|
-
t
|
239
|
+
Sam_data.title = sampleform.title;
|
232
|
-
|
240
|
+
|
233
|
-
t
|
241
|
+
Sam_data.memo = sampleform.memo;
|
242
|
+
|
243
|
+
return Sam_data;
|
234
244
|
|
235
245
|
}
|
236
246
|
|
237
247
|
|
238
248
|
|
249
|
+
@Override
|
250
|
+
|
239
|
-
|
251
|
+
public String toString() {
|
240
|
-
|
241
|
-
|
242
|
-
|
252
|
+
|
243
|
-
|
253
|
+
return "SampleData[id=" + id + ", name=" + name + ", title="
|
244
|
-
|
254
|
+
|
245
|
-
|
255
|
+
+ title + ", memo=" + memo + "]";
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
public static SampleData converttoModel(Sampleform sampleform) {
|
250
|
-
|
251
|
-
// TODO 自動生成されたメソッド・スタブ
|
252
|
-
|
253
|
-
SampleData Sam_data = new SampleData();
|
254
|
-
|
255
|
-
Sam_data.id = StringUtils.isNotEmpty(sampleform.id)?Long.valueOf(sampleform.id):null;
|
256
|
-
|
257
|
-
Sam_data.name = sampleform.name;
|
258
|
-
|
259
|
-
Sam_data.title = sampleform.title;
|
260
|
-
|
261
|
-
Sam_data.memo = sampleform.memo;
|
262
|
-
|
263
|
-
return Sam_data;
|
264
256
|
|
265
257
|
}
|
266
258
|
|
267
|
-
|
268
|
-
|
269
|
-
@Override
|
270
|
-
|
271
|
-
public String toString() {
|
272
|
-
|
273
|
-
return "SampleData[id=" + id + ", name=" + name + ", title="
|
274
|
-
|
275
|
-
+ title + ", memo=" + memo + "]";
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
259
|
}
|
280
260
|
|
281
261
|
```
|
1
内容調整
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,109 @@
|
|
54
54
|
|
55
55
|
```
|
56
56
|
|
57
|
-
|
57
|
+
●Sampleform.java
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
package views.form;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
import java.util.ArrayList;
|
66
|
+
|
67
|
+
import java.util.List;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
import play.data.validation.ValidationError;
|
72
|
+
|
73
|
+
import play.i18n.Messages;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
public class Sampleform {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
public String id ="";
|
82
|
+
|
83
|
+
public String name ="";
|
84
|
+
|
85
|
+
public String title ="";
|
86
|
+
|
87
|
+
public String memo ="";
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
public Sampleform(){}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
public Sampleform(String id,String name,String title,String memo) {
|
96
|
+
|
97
|
+
this.id = id;
|
98
|
+
|
99
|
+
this.name = name;
|
100
|
+
|
101
|
+
this.title = title;
|
102
|
+
|
103
|
+
this.memo = memo;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
public List<ValidationError> validate(){
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
List<ValidationError> errors = new ArrayList<ValidationError>();
|
114
|
+
|
115
|
+
//名前
|
116
|
+
|
117
|
+
if(name == null || name.length() == 0) {
|
118
|
+
|
119
|
+
errors.add(new ValidationError("name",Messages.get("SampleData.name.error")));
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
//タイトル
|
124
|
+
|
125
|
+
if(title == null || title.length() == 0) {
|
126
|
+
|
127
|
+
errors.add(new ValidationError("title",Messages.get("SampleData.title.error")));
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
if(errors.size()>0) {
|
134
|
+
|
135
|
+
System.out.println("Sampleform#validate errors");
|
136
|
+
|
137
|
+
return errors;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
return null;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
@Override
|
150
|
+
|
151
|
+
public String toString() {
|
152
|
+
|
153
|
+
return "Sampleform[id=" + id + ", name=" + name + ", title="
|
154
|
+
|
155
|
+
+ title + ", memo=" + memo + "]";
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
```
|
58
160
|
|
59
161
|
|
60
162
|
|