Return-Path: Delivered-To: apmail-tapestry-commits-archive@minotaur.apache.org Received: (qmail 62085 invoked from network); 8 Jan 2010 13:59:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Jan 2010 13:59:23 -0000 Received: (qmail 26398 invoked by uid 500); 8 Jan 2010 13:59:23 -0000 Delivered-To: apmail-tapestry-commits-archive@tapestry.apache.org Received: (qmail 26359 invoked by uid 500); 8 Jan 2010 13:59: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 26350 invoked by uid 99); 8 Jan 2010 13:59:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jan 2010 13:59:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jan 2010 13:59:14 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id A0C0429A0013 for ; Fri, 8 Jan 2010 05:58:54 -0800 (PST) Message-ID: <1940617239.121021262959134657.JavaMail.jira@brutus.apache.org> Date: Fri, 8 Jan 2010 13:58:54 +0000 (UTC) From: "Geoff Callender (JIRA)" To: commits@tapestry.apache.org Subject: [jira] Commented: (TAP5-725) Last translator in configuration becomes default translator In-Reply-To: <1538044419.1243470105620.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/TAP5-725?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12798017#action_12798017 ] Geoff Callender commented on TAP5-725: -------------------------------------- I've just had the same issue when I tried to implement a PhoneNumberTranslator but as described above it overrode the StringTranslator globally. The aim of my PhoneNumberTranslator is to parse all sorts of client input, removing spaces, hyphens, brackets etc. into a standard format for saving to the DB. On output it formats the phone number based on the rules of the country, adding spaces etc. as required. IMHO this is the role of a Translator, not a Validator. As a hack workaround, I followed Robert Zeigler's suggestion to register my translator as a CharSequence translator rather than a String translator. It works, but it's clearly a hack. See http://thread.gmane.org/gmane.comp.java.tapestry.user/72777/focus=72821 I think we should be able to contribute any number of translators without fear of them globally overriding any others. > Last translator in configuration becomes default translator > ----------------------------------------------------------- > > Key: TAP5-725 > URL: https://issues.apache.org/jira/browse/TAP5-725 > Project: Tapestry 5 > Issue Type: Bug > Components: tapestry-core > Affects Versions: 5.1.0.5 > Reporter: Lukasz Jazgar > Attachments: TrimTranslator.java > > > I've created simple translator TrimTranslator, which works on String fields. It is same as StringTranslator. Only difference is it removes all white spaces at beginning and end of string. I will attach java source file of it. > When I've contributed this translator to TranslatorSource service, new translator became default for type String. Every string value incoming from client is now trimmed. It's wrong. I expect new translator will work only when I explicitly declare it for form field component. > As I see, historically (more than 1 year ago) there was 2 distinct services TranslatorSource and TranslatorDefaultSource. It was clear. > Later they was joined to one. Why? Current TranslatorSource works fine only if there is one translator for every type or we want to override default translator. There is no possibility to create new alternative translators. > Proposal of resolution: > Maybe default translators for type should be distinguished by it's name property, which is unique, not only type? > Default translators should have name same as name of type. So, "string" is default for java.lang.String, "boolean" is default for java.lang.Boolean, and so on. Any other like "trim" or "yesno" (example in jumpstart app) should need explicit declaration. > It boils down to replacing in constructor of TranslatorSourceImpl: > typeToTranslator.put(t.getType(), t); > with: > if (t.getType().getSimpleName().equalsIgnoreCase(t.getName()) { > typeToTranslator.put(t.getType(), t); > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.