Reputation: 3265
Play Framework 1 had a great feature where directly assigning a value to a model property was automatically translated into a function call at runtime. Here are the docs. For example
model.fullname = "John Smith";
would automatically be converted into this under the hood:
model.setFullname("John Smith");
Does the same feature exist in Play Framework 2?
Is it documented anywhere?
Here is a sample java project where I tried to get the feature working in Play 2.1.1. It shows that the getters and setters are being created but that the client byte code isn't being rewritten to call the generated getters and setters.
Upvotes: 4
Views: 1410
Reputation: 33369
Here's an excerpt from the book: Play For Java
Play uses a cool trick called ‘byte code enhancement’ to add getters and setters right after your original code is compiled, and then silently rewrites all your client byte code to use the generated getters and setters. However, if you change from field access to getter/setters, or the other way around, you'll find your code no longer compiles. This is because the bytecode enhancement takes place after your class is compiled, which means it has to actually compile first.
Did you change field access to getter/setter, or the other way around?
Upvotes: 4
Reputation: 5
I am using Play 2.1.0 and getters/setters generation(at a runtime) works for me. In my "target" directory, in classes I can see getter/setter method for all my fields. It is not generating getters/setters only if you already have them in your class. Can you post what in the compiled MyModel.class for you example?
Upvotes: 0