Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-725

Last translator in configuration becomes default translator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 5.1.0.5
    • None
    • tapestry-core
    • None

    Description

      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);
      }

      Attachments

        1. TrimTranslator.java
          0.9 kB
          Lukasz Jazgar

        Activity

          People

            hlship Howard Lewis Ship
            ljazgar Lukasz Jazgar
            Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: