-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow direct field access in Java Forms #8800
Allow direct field access in Java Forms #8800
Conversation
cfe0740
to
4406141
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some comments. I wonder if the default for play.forms.binding.directFieldAccess
should be true
. WDYT?
framework/src/play-java-forms/src/main/java/play/data/DynamicForm.java
Outdated
Show resolved
Hide resolved
framework/src/play-java-forms/src/main/java/play/data/Form.java
Outdated
Show resolved
Hide resolved
framework/src/play-java-forms/src/main/java/play/data/Form.java
Outdated
Show resolved
Hide resolved
framework/src/play-java-forms/src/test/scala/play/data/DynamicFormSpec.scala
Show resolved
Hide resolved
@marcospereira I addressed all your comments plus added two more tests. I would definitely not change First of all you have to know it's either / or. Either you choose These points come into my mind:
As you can see even though I think that our tests would pass (because it looks in our code it's not a problem to make the private fields accessible and we use simple getters without logic everywhere) I would not change the default because that possible would break backward compatibility in user apps. |
Thanks for the explanation, @mkurz. I agree that we should not change the default to
Hum... I can foresee a warning about illegal reflective access in the future then when using Java 8+. But still, this is a configuration that is off by default. Anyway, it would be good to have a note/warning on our docs about it. Could you add a section on |
@marcospereira I added docs that show the usage of direct field access and mentions the risk of warnings and exceptions. |
@marcospereira Are the added docs ok for you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thank you, @mkurz.
* Allow direct field access in Java Forms * Add tests * boolean instead of Boolean * Test for directFieldAccess=false in dynamic form * Test: When only fields (and no getters) exist but direct field access is disabled * Document reference.conf property * Let's be nice - don't break DynamicFormSpec * Documention for direct field access + possible warning * Add forgotten parameters
Backport to 2.7.x: a262d90 |
Fixes https://discuss.lightbend.com/t/databinder-field-access-instead-of-using-accessors/2468
Adds
play.forms.binding.directFieldAccess
config to switch on direct field access for all forms. To control specific forms only this pull request addsform.withDirectFieldAccess(...)
to switch direct field access on or off - or ifnull
falls back to config fallback.