You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Brin <ab...@digitalantiquity.org> on 2017/07/13 18:08:14 UTC
Issues with Localization changes in 2.5.12
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Issues with Localization changes in 2.5.12
Posted by Adam Brin <ab...@digitalantiquity.org>.
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 <lu...@apache.org>
wrote:
> 2017-07-14 14:36 GMT+02:00 Adam Brin <ab...@digitalantiquity.org>:
> > 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278
Re: Issues with Localization changes in 2.5.12
Posted by Lukasz Lenart <lu...@apache.org>.
2017-07-14 14:36 GMT+02:00 Adam Brin <ab...@digitalantiquity.org>:
> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Issues with Localization changes in 2.5.12
Posted by Adam Brin <ab...@digitalantiquity.org>.
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 <lu...@apache.org>
wrote:
> 2017-07-13 20:08 GMT+02:00 Adam Brin <ab...@digitalantiquity.org>:
> > // 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278
Re: Issues with Localization changes in 2.5.12
Posted by Lukasz Lenart <lu...@apache.org>.
2017-07-13 20:08 GMT+02:00 Adam Brin <ab...@digitalantiquity.org>:
> // 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Issues with Localization changes in 2.5.12
Posted by Adam Brin <ab...@digitalantiquity.org>.
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@mail.gmail.com%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 <ab...@digitalantiquity.org> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org