0
양식에 라디오 버튼을 구현하는 방법을 찾는 데 어려움이 있습니다. 나는 1에 등급을 나타내는 해당 그룹의 5 radionbuttons이 필요 5.Play2의 inputRadioGroup에 대한 Java 예제
형태 :
public static class MobileWriteReview {
@Constraints.MinLength(1)
@Constraints.MaxLength(32)
@Constraints.Required
public String firstName;
@Constraints.MinLength(1)
@Constraints.MaxLength(32)
@Constraints.Required
public String lastName;
@Constraints.MinLength(5)
@Constraints.Required
public String password;
@Constraints.MinLength(5)
@Constraints.Required
public String repeatPassword;
@Constraints.Required
public int grade;
@Constraints.MinLength(30)
@Constraints.Required
public String text;
/**
* Required by play.
*/
public MobileWriteReview() {
}
public MobileWriteReview(int grade) {
this.grade = grade;
}
}
컨트롤러 방법 :
private static final Form<MobileWriteReview> MOBILE_WRITE_REVIEW_FORM = form(MobileWriteReview.class);
public static Result review(){
MobileWriteReview mobileWriteReview = new MobileWriteReview(3);
MOBILE_WRITE_REVIEW_FORM.fill(mobileWriteReview);
return ok(mobileInviteToReview.render(MOBILE_WRITE_REVIEW_FORM));
}
public static Result doReview(){
final Form<MobileWriteReview> filledForm = MOBILE_WRITE_REVIEW_FORM.bindFromRequest();
if (filledForm.hasErrors()) {
// User did not fill everything properly
return badRequest(mobileInviteToReview.render(filledForm));
} else {
// Everything was filled
return ok();
}
}
view.scala.html
@(inviteForm: Form[_])
@styles = {
}
@scripts = {
}
@import helper._
@helper.form(routes.MobileInviteToReview.doReview) {
@if(inviteForm.hasGlobalErrors) {
<p class="error">
<span class="label label-important">@inviteForm.globalError.message</span>
</p>
}
@inputRadioGroup(
// appropriate code here
)
}
제 질문은 어떻게하면 내 컨트롤러에서 폼을 설정하고 뷰에서 사용할 수 있습니까?
최신 버전의 Play에서는 2.2.x입니다.보기에서 'helper' 패키지를 통해 양식 헬퍼에 액세스해야합니다. 따라서'@ form'은'@ helper.form'이되고,'@ inputRadioGroup'은'@helper '가됩니다. inputRadioGroup'이고'options = options (...)'는'options = @ helper.options (...)'가됩니다. –