struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Brin <ab...@digitalantiquity.org>
Subject Re: Issues with Localization changes in 2.5.12
Date Thu, 13 Jul 2017 20:52:40 GMT
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 <abrin@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


Mime
View raw message