[ 
https://issues.apache.org/jira/browse/TAP5-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14273428#comment-14273428
 ] 

Michael Dukaczewski edited comment on TAP5-2439 at 9/17/16 6:31 PM:
--------------------------------------------------------------------

No. In fact, it is necessary to write {{Address$Honorific.MR=Mr.}}. With my 
patched version you have to use {{Address.Honorific.MR=Mr.}}.

But there are two other shortcomings in the current implementation:

First, the method {{Enum.name()}} is used if no key in the massage catalog is 
available. As you can read in the Java documentation 
([http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#name%28%29]), 
{{toString}} should be preferred here.

In addition, the labels are generated in a util class by a static method. So 
there is no way to override the label generation. A more elegant way would be 
to use a service here. For example, if you have to read the labels from a 
database.



was (Author: mduka):
No. In fact, it is necessary to write {{Address$Honorific.MR=Mr.}}. With my 
patched version you have to use {{Address.Honorific.MR=Mr.}}.

But there are two other shortcomings in the current implementation:

First, the method {{Enum.name()}} is used if no key in the massage catalog is 
available. As you can read in the Java documentation 
([http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#name%28%29]), 
{{toString}} should be preferred here.

In addition, the labels are generated in a util class by a static method. So 
there is a way to override the label generation. A more elegant way would be to 
use a service here. For example, if you have to read the labels from a database.


> Inconsistent label keys in message catalog for enums defined in inner classes
> -----------------------------------------------------------------------------
>
>                 Key: TAP5-2439
>                 URL: https://issues.apache.org/jira/browse/TAP5-2439
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-core
>    Affects Versions: 5.4
>            Reporter: Michael Dukaczewski
>         Attachments: Address.java, Example.java, Example.properties, 
> Example.tml, TapestryInternalUtils.java
>
>
> When customizing the label of an enum that is defined inside a class two 
> different key in the message catalog are needed.
> Example, given the following class:
> {code:title=Address.java}
> public class Address {
>    public enum Honorific {MR, MRS, MISS, DR}
>    // [...]
> }
> {code}
> Two entries per value in the message catalog are needed to get a consistent 
> output:
> {code:title=app.properties}
> Honorific.MR=Mr.
> Address$Honorific.MR=Mr.
> {code}
> The problem is that there are two different methods in TapestryInternalUtils 
> to get a label for an enum:
> {code:title=TapestryInternalUtils.java}
> String getLabelForEnum(Messages messages, String prefix, Enum value)
> String getLabelForEnum(Messages messages, Enum value)
> {code}
> The former is called by EnumSelectModel, where the latter is used by 
> PropertyDisplayBlocks.
> Although the second method calls the first, but here the prefix is generated 
> by TapestryInternalUtils.lastTerm(). In the other callings of the first 
> method Class.toSimpleName() is used, which does not produce the same result.
> I think the best solution would be to remove the method with 3 arguments 
> completely, because there is no meaningful use for it. All labels for an enum 
> should be generated consistent in the same way.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to