원할 때 표준 검증 유효성 검사를 무시할 수 있는지 여부를 알고 싶습니다. 예를 들어, 그때, 그냥 명확하게하기 위해다른보기에서 재생 프레임 워크 양식 오류 무시
@Entity
public class Car{
@Id
private Long id;
@Required
private String model;
@Required
private String hiddenField; //important but doesn't appear in some cases (some usecases)
}
같은 엔터티라는 자동차를 가정 해 봅시다
사례 1
@(carForm : Form[Car])
@import helper._
@form(routes.controller.foo.bar) {
@inputText(carForm("model"))
<input type="submit">
}
사례 2
@(carForm : Form[Car])
@import helper._
@form(routes.controller.foo.bar) {
@inputText(carForm("model"))
@inputText(carForm("hiddenField"))
<input type="submit">
}
그런 다음 Play.data.Form 개체가 있고 모델 또는 e로 주어진 hiddenField를 채우지 않았기 때문에 오류가 발생합니다. xmple. 그러나 실제로,이 숨겨진 된 경우조차 보이지 않는 경우가 있습니다 (사례 1), 사용자가 그 시간을 편집 할 수 없으므로 입력이 없습니다. 그래서, 두 개의 유스 케이스가 있다면, 처음에는 모든 입력이 있고 그것들은 채워져 있어야하지만, 다른 하나는 'hiddenField'입력이 없지만, 내 모델에서는 여전히 필요합니다. 물론, 그것없이 제출 된 양식도 오류가 있습니다. 어떻게해야합니까?. 어떻게 처리해야 했습니까? 하나의 모델을 가지고 있지만 유효성 검사는 다른 경우에 따라 다를 수 있으며 jquery 또는 순수한 javascript가 아닌 서버 측이어야합니다.
나는, 그런
MyForm<Car> myCarForm = Form.form(Car.class).bindFromRequest();
//it has errors, sure it does, hiddenField was required and that field didn't even exist at screen.
myCarForm.discardErrors(); //ok, error hashmap is empty right now
myCarForm.get(); // anyway, no value here.
//myCarForm.data(); //for sure i could retrieve field by field and remount object that way, but that looks hacky and hardworking
모든 솔루션을 (이 경우 1에서 제출 된 상상) 통해 discardErrors를 시도? 모두에게 감사합니다
감사합니다. 그런데 어떻게 검증 플레이가 사용할 것인지 선택할 수 있습니까? 나는 유즈 케이스와 다른 유스 케이스를 원하지만 그 방법은 항상 호출됩니다. – user7197