1
Game
이라는 간단한 엔티티가 있습니다. 사용자가 한 번에 여러 항목을 수정할 수있게하고 싶습니다. 따라서 복수 Game
엔티티가 포함 된 양식이 필요합니다.Ad-Hoc 유효성 검사가 수행되지 않았습니다.
문제점 : 양식이 제출되고 hasErrors()
을 호출 할 때 Game
엔티티에있는 내 사용자 정의 ad-hoc validate
메소드가 호출되지 않습니다. 주석으로 표시된 유효성 검사 만 검사되고 유효하지 않은 경우 오류가 생성됩니다.
이
은Game
엔티티입니다 :
@Entity
public class Game extends Model {
@Id
public Long id;
@ManyToOne
@Constraints.Required
public Team team1;
@ManyToOne
@Constraints.Required
public Team team2;
//the validate method does not get called
public String validate()
{
System.out.println("Validating the Game Entity.");
if(team1.id == team2.id)
return "You have to choose two different teams!";
return null;
}
public static Model.Finder<Long,Game> find = new Model.Finder<Long,Game>(Long.class, Game.class);
}
이 여러에게 Game
엔티티가 들어있는 형태입니다.
public class GameForm {
@Valid
public List<Game> games;
public GameForm()
{
games = new ArrayList<Game>();
}
}
이것은 컨트롤러 메서드입니다.
public static Result save()
{
Form<GameForm> gameForm = form(GameForm.class).bindFromRequest();
if(gameForm.hasErrors())
return badRequest(create.render(gameForm));
return redirect(
routes.Games.index()
);
}