Issues with Localization changes in 2.5.12

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Issues with Localization changes in 2.5.12

adam brin
Hi,
  With the removal of the TextProviderFactory and it’s replacement with beans, I can’t figure out how to properly setup our test environment (when testing Controllers that are autowired by spring.  How do I inject a custom resourceBundle into the ActionContext or stack?  I used to be able to create my own textProvider, but this no longer works.    I’ve seen code like the following in the struts2 tests, but localizedTextProvider is null here:

        LocalizedTextProvider localizedTextProvider = container.getInstance(LocalizedTextProvider.class);

I think if I can get the localizedTextProvider properly installed into the container, I’d be fine, but I can’t see how to do that. Here’s our setup code that worked with Struts 2.5.10:


   T controller = applicationContext.getBean(controllerClass);
        if (controller instanceof AbstractAuthenticatableAction) {
            TdarActionSupport tas = (TdarActionSupport) controller;
            tas.setServletRequest(getServletRequest());
            tas.setServletResponse(getServletResponse());
            // set the context
        }
        Map<String, Object> contextMap = new HashMap<String, Object>();
        contextMap.put(StrutsStatics.HTTP_REQUEST, getServletRequest());
        ActionContext context = new ActionContext(contextMap);
        context.setLocale(Locale.getDefault());

        ConfigurationManager configurationManager = new ConfigurationManager();
        OgnlValueStackFactory factory = new OgnlValueStackFactory();

        // FIXME: needs to be a better way to handle this
        TextProviderFactory textProviderFactory = new TextProviderFactory();

        factory.setTextProvider(textProviderFactory.createInstance(getResourceBundle(), (LocaleProvider) controller));

        configurationManager.addContainerProvider(new XWorkConfigurationProvider());
        configurationManager.getConfiguration().getContainer().inject(factory);
        if (controller instanceof ActionSupport) {
            ((ActionSupport) controller).setContainer(configurationManager.getConfiguration().getContainer());
        }
        ValueStack stack = factory.createValueStack();

        context.setValueStack(stack);
        ActionContext.setContext(context);
--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with Localization changes in 2.5.12

adam brin
Figured this out:


        Map<String, Object> contextMap = new HashMap<String, Object>();
        contextMap.put(StrutsStatics.HTTP_REQUEST, getServletRequest());
        ActionContext context = new ActionContext(contextMap);
        context.setLocale(Locale.getDefault());
        // http://mail-archives.apache.org/mod_mbox/struts-user/201001.mbox/%3C637b76e41001151852x119c9cd4vbbe6ff560e56e46f@...%3E

        ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
        OgnlValueStackFactory factory = new OgnlValueStackFactory();
        configurationManager.addContainerProvider(new XWorkConfigurationProvider());
        configurationManager.reload();
        Container container = configurationManager.getConfiguration().getContainer();
        container.inject(factory);

        LocalizedTextProvider instance = container.getInstance(LocalizedTextProvider.class);
        instance.addDefaultResourceBundle(“…");




--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278

> On Jul 13, 2017, at 11:08 AM, Adam Brin <[hidden email]> wrote:
>
> Hi,
>  With the removal of the TextProviderFactory and it’s replacement with beans, I can’t figure out how to properly setup our test environment (when testing Controllers that are autowired by spring.  How do I inject a custom resourceBundle into the ActionContext or stack?  I used to be able to create my own textProvider, but this no longer works.    I’ve seen code like the following in the struts2 tests, but localizedTextProvider is null here:
>
>        LocalizedTextProvider localizedTextProvider = container.getInstance(LocalizedTextProvider.class);
>
> I think if I can get the localizedTextProvider properly installed into the container, I’d be fine, but I can’t see how to do that. Here’s our setup code that worked with Struts 2.5.10:
>
>
>   T controller = applicationContext.getBean(controllerClass);
>        if (controller instanceof AbstractAuthenticatableAction) {
>            TdarActionSupport tas = (TdarActionSupport) controller;
>            tas.setServletRequest(getServletRequest());
>            tas.setServletResponse(getServletResponse());
>            // set the context
>        }
>        Map<String, Object> contextMap = new HashMap<String, Object>();
>        contextMap.put(StrutsStatics.HTTP_REQUEST, getServletRequest());
>        ActionContext context = new ActionContext(contextMap);
>        context.setLocale(Locale.getDefault());
>
>        ConfigurationManager configurationManager = new ConfigurationManager();
>        OgnlValueStackFactory factory = new OgnlValueStackFactory();
>
>        // FIXME: needs to be a better way to handle this
>        TextProviderFactory textProviderFactory = new TextProviderFactory();
>
>        factory.setTextProvider(textProviderFactory.createInstance(getResourceBundle(), (LocaleProvider) controller));
>
>        configurationManager.addContainerProvider(new XWorkConfigurationProvider());
>        configurationManager.getConfiguration().getContainer().inject(factory);
>        if (controller instanceof ActionSupport) {
>            ((ActionSupport) controller).setContainer(configurationManager.getConfiguration().getContainer());
>        }
>        ValueStack stack = factory.createValueStack();
>
>        context.setValueStack(stack);
>        ActionContext.setContext(context);
> --
> _________________________________________________________
> Adam Brin
> Director of Technology, Digital Antiquity
> 480.965.1278
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with Localization changes in 2.5.12

Lukasz Lenart
In reply to this post by adam brin
2017-07-13 20:08 GMT+02:00 Adam Brin <[hidden email]>:
>         // FIXME: needs to be a better way to handle this
>         TextProviderFactory textProviderFactory = new TextProviderFactory();

I think you can simple use StrutsTextProviderFactory instead - it
works exactly the same way.


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with Localization changes in 2.5.12

adam brin
I think I tried that originally without help. Anyway, it seems like my fix
worked.

On Thu, Jul 13, 2017 at 10:41 PM, Lukasz Lenart <[hidden email]>
wrote:

> 2017-07-13 20:08 GMT+02:00 Adam Brin <[hidden email]>:
> >         // FIXME: needs to be a better way to handle this
> >         TextProviderFactory textProviderFactory = new
> TextProviderFactory();
>
> I think you can simple use StrutsTextProviderFactory instead - it
> works exactly the same way.
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with Localization changes in 2.5.12

Lukasz Lenart
2017-07-14 14:36 GMT+02:00 Adam Brin <[hidden email]>:
> I think I tried that originally without help.

"without help" -> it didn't work?


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with Localization changes in 2.5.12

adam brin
Unfortunately, using the factory alone didn't help because we needed to add
the ResourceBuindles into the TextProviderInstance

On Fri, Jul 14, 2017 at 6:16 AM, Lukasz Lenart <[hidden email]>
wrote:

> 2017-07-14 14:36 GMT+02:00 Adam Brin <[hidden email]>:
> > I think I tried that originally without help.
>
> "without help" -> it didn't work?
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278
Loading...