Tapestry 5
  1. Tapestry 5
  2. TAP5-253

Unable to effectively override default validation messages globally

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 5.0.15
    • Fix Version/s: 5.0.16
    • Component/s: tapestry-core
    • Labels:
      None

      Description

      I'm trying to set up validation for our forms and I need to customize the default validation messages. Unfortunately there doesn't seem to be a way to do this as contributing to ValidationMessagesSource just adds new messages for new validators. I need to change the default messages to what we need.

      I know that we can override the message for each field name in the message catalogs, but this is undesirable (& expensive with extra translations needed) because they'll all be the same. The only solution I've found is to override this with a properties file in the tapestry5.internal package but this doesn't work in every environment so it's not really a good solution.

        Activity

        Howard M. Lewis Ship made changes -
        Resolution Fixed [ 1 ]
        Status In Progress [ 3 ] Closed [ 6 ]
        Fix Version/s 5.0.16 [ 12313427 ]
        Howard M. Lewis Ship made changes -
        Summary Default validation messages only overridable individually Unable to effectively override default validation messages globally
        Description I'm trying to set up validation for our forms and I need to customise the default validation messages. Unfortunately there doesn't seem to be a way to do this as contributing to ValidationMessagesSource just adds new messages for new validators. I need to change the default messages to what we need.

        I know that we can override the message for each field name in the message catalogs, but this is undesirable (& expensive with extra translations needed) because they'll all be the same. The only solution I've found is to override this with a properties file in the tapestry5.internal package but this doesn't work in every environment so it's not really a good solution.
        I'm trying to set up validation for our forms and I need to customize the default validation messages. Unfortunately there doesn't seem to be a way to do this as contributing to ValidationMessagesSource just adds new messages for new validators. I need to change the default messages to what we need.

        I know that we can override the message for each field name in the message catalogs, but this is undesirable (& expensive with extra translations needed) because they'll all be the same. The only solution I've found is to override this with a properties file in the tapestry5.internal package but this doesn't work in every environment so it's not really a good solution.
        Hide
        Howard M. Lewis Ship added a comment -

        My original thought with ValidationMessagesSource was that a new 3rd party validator or translator that wanted to provide its own set of default validation messages would contribute its own bundle. Order wasn't important (thus Collection, not List) since there would not be any naming conflicts; it would be entirely new keys.

        However, I now understand the desire to override built-in messages using a secondary bundle.

        I think this can be taken care of, it will affect the contributions, since it will now be an OrderedConfiguration.

        Show
        Howard M. Lewis Ship added a comment - My original thought with ValidationMessagesSource was that a new 3rd party validator or translator that wanted to provide its own set of default validation messages would contribute its own bundle. Order wasn't important (thus Collection, not List) since there would not be any naming conflicts; it would be entirely new keys. However, I now understand the desire to override built-in messages using a secondary bundle. I think this can be taken care of, it will affect the contributions, since it will now be an OrderedConfiguration.
        Howard M. Lewis Ship made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Howard M. Lewis Ship made changes -
        Field Original Value New Value
        Assignee Howard M. Lewis Ship [ hlship ]
        Hide
        Thiago H. de Paula Figueiredo added a comment -

        The ValidationMessagesSource contribution does not work even when you add a properties file for a locale that Tapestry does not have default messages yet.

        I've added this method to my AppModule.

        public static void contributeValidationMessagesSource(Configuration<String> configuration)

        { configuration.add("classpath:/ValidationMessages"); }

        After a lot of digging and debugging in the tapestry-core sources, I've found that in the ValidationMessagesSourceImpl.ValidationMessagesSourceImpl(Collection<String> bundles, Resource classpathRoot, URLChangeTracker tracker), that my ValidationMessages.properties is used as the parent bundle to the default Tapestry validation properties file. It should be exactly the other way. My validation messages do not override the defaults.

        Shouldn't the ValidationMessagesSource service receive an OrderedConfiguration intead of a Configuration? The ordering of the contributions seems to be an issue here.

        Show
        Thiago H. de Paula Figueiredo added a comment - The ValidationMessagesSource contribution does not work even when you add a properties file for a locale that Tapestry does not have default messages yet. I've added this method to my AppModule. public static void contributeValidationMessagesSource(Configuration<String> configuration) { configuration.add("classpath:/ValidationMessages"); } After a lot of digging and debugging in the tapestry-core sources, I've found that in the ValidationMessagesSourceImpl.ValidationMessagesSourceImpl(Collection<String> bundles, Resource classpathRoot, URLChangeTracker tracker), that my ValidationMessages.properties is used as the parent bundle to the default Tapestry validation properties file. It should be exactly the other way. My validation messages do not override the defaults. Shouldn't the ValidationMessagesSource service receive an OrderedConfiguration intead of a Configuration? The ordering of the contributions seems to be an issue here.
        Andy Blower created issue -

          People

          • Assignee:
            Howard M. Lewis Ship
            Reporter:
            Andy Blower
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development