Return-Path: Delivered-To: apmail-tapestry-commits-archive@minotaur.apache.org Received: (qmail 76541 invoked from network); 26 Feb 2011 22:52:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Feb 2011 22:52:22 -0000 Received: (qmail 63456 invoked by uid 500); 26 Feb 2011 22:52:22 -0000 Delivered-To: apmail-tapestry-commits-archive@tapestry.apache.org Received: (qmail 63429 invoked by uid 500); 26 Feb 2011 22:52:22 -0000 Mailing-List: contact commits-help@tapestry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tapestry.apache.org Delivered-To: mailing list commits@tapestry.apache.org Received: (qmail 63421 invoked by uid 99); 26 Feb 2011 22:52:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Feb 2011 22:52:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Feb 2011 22:52:19 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id A99E51B76A8 for ; Sat, 26 Feb 2011 22:51:58 +0000 (UTC) Date: Sat, 26 Feb 2011 22:51:58 +0000 (UTC) From: "Paul Stanton (JIRA)" To: commits@tapestry.apache.org Message-ID: <812572672.469.1298760718691.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1668506292.463.1298760478790.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] Commented: (TAP5-1452) messages property lookup for enum values is inconsistent, and incorrect MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/TAP5-1452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999852#comment-12999852 ] Paul Stanton commented on TAP5-1452: ------------------------------------ Also, it's probably a good idea to return "" or null if value parameter is null. > messages property lookup for enum values is inconsistent, and incorrect > ----------------------------------------------------------------------- > > Key: TAP5-1452 > URL: https://issues.apache.org/jira/browse/TAP5-1452 > Project: Tapestry 5 > Issue Type: Bug > Components: tapestry-core > Affects Versions: 5.2.4, 5.1.0.7 > Reporter: Paul Stanton > Priority: Minor > > I work on a project which has a few different entities each with their own specific ranges of potential values for 'Category'. The way this project has achieved this is to inline Enums within the entity class. Unfortunately, the classes all define an enum named "Category", ie: > public class EntityOne > { > enum Category {...}; > private Category category; > .... > } > public class EntityTwo > { > enum Category {...}; > private Category category; > .... > } > The EnumSelectModel uses TapestryInternalUtils.getLabelForEnum(Messages messages, String prefix, Enum value) where prefix is enumClass.getSimpleName() > This makes it impossible to differentiate inline enums in different classes with the same name since EntityOne.Category and EntityTwo.Category would both have the prefix "Category". > After doing some further digging I also found that there was another way to resolve a message for an enum value: TapestryInternalUtils.getLabelForEnum(Messages messages, Enum value) which is used by PropertyDisplayBlocks. This method is slightly better since it would look for EntityOne$Category instead of just Category, however I think it would be better still to use the fully qualified name. > I think it is important to > a) be consistent > b) allow for all cases > Here is my solution: > 1. scrap TapestryInternalUtils.getLabelForEnum(Messages messages, String prefix, Enum value) and move the cascading logic into TapestryInternalUtils.getLabelForEnum(Messages messages, Enum value), update EnumSelectModel to use TapestryInternalUtils.getLabelForEnum(Messages messages, Enum value). > 2. change the cascading lookup logic to > a) test for [value.getClass().getName() + "." + value.name()] > b) test for [lastTerm(value.getClass().getName()) + "." + value.name()] > c) test for [value.getClass().getSimpleName() + "." + value.name()] > d) test for [value.name()] > The code: > public static String getLabelForEnum(Messages messages, Enum value) > { > String key1 = value.getClass().getName() + "." + value.name(); > if (messages.contains(key1)) > return messages.get(key1); > String key2 = lastTerm(value.getClass().getName()) + "." + value.name(); > if (messages.contains(key2)) > return messages.get(key2); > String key3 = value.getClass().getSimpleName() + "." + value.name(); > if (messages.contains(key3)) > return messages.get(key3); > String key4 = value.name(); > if (messages.contains(key4)) > return messages.get(key4); > return toUserPresentable(value.name().toLowerCase()); > } > EnumSelectModel and PropertyDisplayBlocks could use this without issue and be fully backwards compatible with previously defined message properties. -- This message is automatically generated by JIRA. - For more information on JIRA, see: http://www.atlassian.com/software/jira