Hi Jens,
I was looking into static fields and the @Property annotation worker the
other day but stopped, as I realized you can use "public static final"
fields directly in the TML without any additional work.
So the following code should be fine:
public final String[] keys = new String[] {
"A", "B", "C"
};
Use it as usual, like "prop:keys" in the TML
Private fields that are only exposed to the TML would be preferable, but
it's a simple workaround, and I'm not sure how easy it would be to
implement it in the PlasticClass transformation.
The change in final handling is most likely related to an older ticket of
mine
https://issues.apache.org/jira/browse/TAP5-2630
Cheers
Ben
On Tue, Aug 1, 2023 at 2:57 PM Jens Breitenstein <jb//
[email protected]> wrote:
> HI!
>
> I noticed due to JDK 11 there is a subtile change in handling of final
> fields and initialization.
>
> On rare cases we used final fields including @Property(write = false),
> which is no longer working. Example:
>
> @Property(write="false") private final String[] _keys = new String[] {
> "A", "B", "C"
> };
>
> This allowed us to initialize the field once, but still access it from
> the page (tml). Using JDK 11 and T5.8.x this now throws an exception.
> But modifying it to
>
> private static final String[] _keys = new String[] {
> "A", "B", "C"
> };
>
> public String[] getKeys() {
> return _keys;
> };
>
> requires an additional instance method, because @Property can't handle
> static fields. Are there any plans to solve it by Tapestry itself (eg to
> add this "get" method automatically while class transformation is
> applyed in case a field is marked as static and and property)?
>
> Currently I do not see another workaround apart rewriting parts like
> this, right?
>
> Thanks
>
> Jens
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>