Web アプリケーションに Play 2.0 を使用しています。Play のプロパティ シミュレーションについて知りました: http://www.playframework.org/documentation/1.2.3/model#properties
サンプル アプリケーションで同じことを試したところ、setter の検証が呼び出されませんでした。
アプリケーションをデバッグ モードで再実行し、Product クラスの Setter メソッドにブレーク ポイントを設定しましたが、実行されません。
コード スニペットは次のとおりです。
public class Product {
public String name;
public Integer price;
public void setPrice(Integer price) {
if (price < 0) {
throw new IllegalArgumentException("Price can’t be negative!");
}
this.price = price;
}
}
public class Application extends Controller {
public static Result index() {
Product p=new Product();
p.name="Test";
p.price=-1; //I am expecting that code will throw IllegalArgumentException but its not
return ok(index.render(p.name));
}
}
ここで何か不足していますか?