Take the 2-minute tour ×

I am using Play 2.0 for webapplication. I came to know about Play's property simulation:http://www.playframework.org/documentation/1.2.3/model#properties

When I tried same thing on my sample application setter's validation did not get called.

I re run application in debug mode and put break point on Setter method of Product class but its not getting executed.

Here is code snippet :

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.price=-1; //I am expecting that code will throw IllegalArgumentException but its not

      return ok(index.render(p.name));


Am I missing something here ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Play 2 behaves different than play 1.

It won't rewrite that expressions:

anInstance.field = newValue;

So you have to call the setter directly to validate arguments.

Source: https://groups.google.com/forum/#!topic/play-framework/S8DHAcYHh-A

share|improve this answer
Thanks Schleichardt –  Rutvij Shah Oct 7 '12 at 5:24

Your Answer


