struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Lenart (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (WW-4829) Set a global resource bundle in class
Date Tue, 01 Aug 2017 09:58:00 GMT

    [ https://issues.apache.org/jira/browse/WW-4829?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16108655#comment-16108655
] 

Lukasz Lenart edited comment on WW-4829 at 8/1/17 9:57 AM:
-----------------------------------------------------------

I would do it like this

{code:java}
public class MyTextProviderFactory implements TextProviderFactory {

    protected LocaleProviderFactory localeProviderFactory;
    protected LocalizedTextProvider localizedTextProvider;
    
    @Inject
    public MyTextProviderFactory(LocaleProviderFactory localeProviderFactory, LocalizedTextProvider
localizedTextProvider) {
        this.localeProviderFactory = localeProviderFactory;
        this.localizedTextProvider = localizedTextProvider;
        
        this.localizedTextProvider.addDefaultResourceBundle("myBundle");
    }

    @Override
    public TextProvider createInstance(Class clazz) {
        TextProvider instance = getTextProvider(clazz);
        if (instance instanceof ResourceBundleTextProvider) {
            ((ResourceBundleTextProvider) instance).setClazz(clazz);
            ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
        }
        return instance;
    }

    @Override
    public TextProvider createInstance(ResourceBundle bundle) {
        TextProvider instance = getTextProvider(bundle);
        if (instance instanceof ResourceBundleTextProvider) {
            ((ResourceBundleTextProvider) instance).setBundle(bundle);
            ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
        }
        return instance;
    }

    protected TextProvider getTextProvider(Class clazz) {
        return new TextProviderSupport(clazz, localeProviderFactory.createLocaleProvider(),
localizedTextProvider);
    }

    protected TextProvider getTextProvider(ResourceBundle bundle) {
        return new TextProviderSupport(bundle, localeProviderFactory.createLocaleProvider(),
localizedTextProvider);
    }

}
{code}


was (Author: lukaszlenart):
I would do it like this

{code:java}
public class MyTextProviderFactory implements TextProviderFactory {

    protected LocaleProviderFactory localeProviderFactory;
    protected LocalizedTextProvider localizedTextProvider;
    
    @Inject
    public StrutsTextProviderFactory(LocaleProviderFactory localeProviderFactory, LocalizedTextProvider
localizedTextProvider) {
        this.localeProviderFactory = localeProviderFactory;
        this.localizedTextProvider = localizedTextProvider;
        
        this.localizedTextProvider.addDefaultResourceBundle("myBundle");
    }

    @Override
    public TextProvider createInstance(Class clazz) {
        TextProvider instance = getTextProvider(clazz);
        if (instance instanceof ResourceBundleTextProvider) {
            ((ResourceBundleTextProvider) instance).setClazz(clazz);
            ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
        }
        return instance;
    }

    @Override
    public TextProvider createInstance(ResourceBundle bundle) {
        TextProvider instance = getTextProvider(bundle);
        if (instance instanceof ResourceBundleTextProvider) {
            ((ResourceBundleTextProvider) instance).setBundle(bundle);
            ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
        }
        return instance;
    }

    protected TextProvider getTextProvider(Class clazz) {
        return new TextProviderSupport(clazz, localeProviderFactory.createLocaleProvider(),
localizedTextProvider);
    }

    protected TextProvider getTextProvider(ResourceBundle bundle) {
        return new TextProviderSupport(bundle, localeProviderFactory.createLocaleProvider(),
localizedTextProvider);
    }

}
{code}

> Set a global resource bundle in class 
> --------------------------------------
>
>                 Key: WW-4829
>                 URL: https://issues.apache.org/jira/browse/WW-4829
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.5.12
>            Reporter: Alireza Fattahi
>             Fix For: 2.5.13
>
>
> In struts 2.5.12 the *LocalizedTextUtil* is removed.
> We used to `*LocalizedTextUtil.addDefaultResourceBundle*` in our classes to add resource
bundles. This was mentioned in https://struts.apache.org/docs/how-do-i-set-a-global-resource-bundle.html
> Can you please let me know how this can be done with this change ?!



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message