Hi Jens,

I finally found some free time to take a look, but I can't reproduce your
issue with the current HEAD.

PAGE:

public class StaticFieldAsPropertyDemo {
    public static int[] INT_ARRAY = {1, 3, 5, 7, 9};
    public static final String CONSTANT = "this is a constant";
}


TML:

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";
      t:type="Border">

    <h1>Static Field As Property Demo</h1>

    <t:intarraywriter array="prop:INT_ARRAY"/>

    <span>${prop:CONSTANT}</span>

</html>


I put this into the tapestry-core integration tests, added a unit test, and
it succeeds without a problem (Java 11/17).

Do you have any more info, or could you share a simplified sample project
that I can run on my machine?

Cheers
Ben

On Tue, Aug 1, 2023 at 4:46 PM Ben Weidig <b...@netzgut.net> wrote:

> That's weird...
>
> Here's an example from my code with some custom types:
>
> public static final List<WeekDay> WEEK_DAY_SOURCE = List.of(...);
>
> In the TML:
>
> <t:loop
>     t:source="prop:WEEK_DAY_SOURCE"
>     t:value="prop:weekDay">
>     ...
> </t:loop>
>
> Works fine for me, but I'm running 5.8.2 with OpenJDK 17, not 11.
>
>
>
> On Tue, Aug 1, 2023 at 4:29 PM Jens Breitenstein <jb//
> j-b-s...@toc-mailserver.de> wrote:
>
>> Sorry, Ben, tried it, but this is not working.
>>
>>
>>      private final String x = "...";
>>      public final String x = "...";
>>
>> throws: "Update to non-static final field ...x... attempted from a
>> different method (initializeInstance) than the initializer method <init>"
>> which is correct, because the field isn't static.
>>
>>
>> Using
>>
>>      private static final String x = "...";
>>
>> works, but requires additional get method.
>>
>>
>> In contrast
>>
>>      public static final String x = "...";
>>
>> is not accessible from the page (tml). Exception is:
>>
>> "Exception assembling root component of page X: Could not convert 'x'
>> into a component parameter binding: Exception generating conduit for
>> expression 'x': Class X does not contain a property (or public field)
>> named 'x'.
>>
>>
>> Tested with T5.8.3 and OpenJDK 11.07
>>
>>
>> Jens
>>
>>
>>
>> Am 01.08.23 um 15:29 schrieb Ben Weidig:
>> > 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//
>> > j-b-s...@toc-mailserver.de> 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: users-unsubscr...@tapestry.apache.org
>> >> For additional commands, e-mail: users-h...@tapestry.apache.org
>> >>
>> >>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>>
>
>

Reply via email to