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

Direct instantiation of ComponentResourceSelector should be replaced with delegation to ComponentRequestSelectorAnalyzer

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.6.2, 5.7.0
    • tapestry-core
    • None

    Description

      Some implementation methods in tapestry core still use direct instantiation of ComponentResourceSelector instead of delegating to ComponentRequestSelectorAnalyzer, namely:

      in ComponentMessageSourceImpl.java

       

      public Messages getMessages(ComponentModel componentModel, Locale locale)
      {
          return getMessages(componentModel, new ComponentResourceSelector(locale));
      }
      public Messages getApplicationCatalog(Locale locale)
      {
          return messagesSource.getMessages(appCatalogBundle, new ComponentResourceSelector(locale));
      } 
      

      in ComponentTemplateSourceImpl.java

       

      public ComponentTemplate getTemplate(ComponentModel componentModel, Locale locale)
      {
          return getTemplate(componentModel, new ComponentResourceSelector(locale));
      }

      Which makes it impossible to use axes with message bundles and component templates.

       

      Default implementation of ComponentRequestSelectorAnalyzer interface uses ThreadLocale instead of directly passed Locale instance. To workaround this above methods may temporarily set passed locale into ThreadLocal and restore original value after `#buildSelectorForRequest` is returned, i.e.:

      public Messages getMessages(ComponentModel componentModel, Locale locale)
      {
          Locale original = threadLocale.getLocale();
      
          try
          {
              threadLocale.setLocale(locale);
      
              return getMessages(componentModel, analyzer.buildSelectorForRequest());
          }
          finally
          {
              threadLocale.setLocale(original);
          }
      }

      {{}}

       

      Attachments

        Activity

          People

            thiagohp Thiago Henrique De Paula Figueiredo
            dmitrygusev Dmitry Gusev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: