struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alireza Fattahi (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (WW-4830) Override TextProvider doesnot work in struts 2.5.12
Date Mon, 31 Jul 2017 04:21:01 GMT

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

Alireza Fattahi edited comment on WW-4830 at 7/31/17 4:20 AM:
--------------------------------------------------------------

It worked, the sample helped a lot.

I will put some code here for others who may read :)

{code:xml}
<constant name="struts.xworkTextProvider" value="DefaultTextProvider" />
<bean type="com.opensymphony.xwork2.TextProvider" name="DefaultTextProvider" class="utils.CustomTextProvider"
scope="default" />


{code}


And
{code:java}

public class CustomStrutsTextProviderFactory extends StrutsTextProviderFactory {
	
	@Override
	protected TextProvider getTextProvider(Class clazz) {
               //If you want to optionaly add some resource bundles dynamically you can do
it here
		//localizedTextProvider.addDefaultResourceBundle("messages/label");
		//localizedTextProvider.addDefaultResourceBundle("messages/customerA/label");
		return new CustomTextProvider(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
	}

	@Override
	protected TextProvider getTextProvider(ResourceBundle bundle) {
                 //If you want to optionaly add some resource bundles dynamically you can
do it here
		//localizedTextProvider.addDefaultResourceBundle("messages/label");
		//localizedTextProvider.addDefaultResourceBundle("messages/customerA/label");

		return new CustomTextProvider(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
	}
}

{code}

And the CustomTextProvider  which you can play with get text.

{code:java}

public class CustomTextProvider extends TextProviderSupport {

	public CustomTextProvider(Class<?> clazz, LocaleProvider provider, LocalizedTextProvider
localizedTextProvider) {
	        super(clazz, provider, localizedTextProvider);
	    }

	public CustomTextProvider(ResourceBundle bundle, LocaleProvider provider, LocalizedTextProvider
localizedTextProvider) {
	        super(bundle, provider, localizedTextProvider);
	}

        public String getText(String key, String defaultValue, List<?> args) {
            String text = super.getText(key, defaultValue, args);
            //Do some thing with text
          //for example return text.trim();
      }

   //Override other getText if you need


{code}

Please correct me. Thanks for the help


was (Author: afattahi):
It worked, the sample helped a lot.

I will put some code here for others who may read :)

{code:xml}
<constant name="struts.xworkTextProvider" value="DefaultTextProvider" />
<bean type="com.opensymphony.xwork2.TextProvider" name="DefaultTextProvider" class="utils.CustomTextProvider"
scope="default" />


{code}


And
{code:java}

public class CustomStrutsTextProviderFactory extends StrutsTextProviderFactory {
	
	@Override
	protected TextProvider getTextProvider(Class clazz) {
               //If you want to optionaly add some resource bundles dynamically you can do
it here
		//localizedTextProvider.addDefaultResourceBundle("messages/label");
		//localizedTextProvider.addDefaultResourceBundle("messages/customerA/label");
		return new CustomTextProvider(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
	}

	@Override
	protected TextProvider getTextProvider(ResourceBundle bundle) {
                 //If you want to optionaly add some resource bundles dynamically you can
do it here
		//localizedTextProvider.addDefaultResourceBundle("messages/label");
		//localizedTextProvider.addDefaultResourceBundle("messages/customerA/label");

		return new CustomTextProvider(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
	}
}

{code}

And the CustomTextProvider  which you can play with get text.

{code:java}

public class CustomTextProvider extends TextProviderSupport {

	public CustomTextProvider(Class<?> clazz, LocaleProvider provider, LocalizedTextProvider
localizedTextProvider) {
	        super(clazz, provider, localizedTextProvider);
	    }

	public CustomTextProvider(ResourceBundle bundle, LocaleProvider provider, LocalizedTextProvider
localizedTextProvider) {
	        super(bundle, provider, localizedTextProvider);
	}

        public String getText(String key, String defaultValue, List<?> args) {
            String text = super.getText(key, defaultValue, args);
            //Do some thing with text
          return;
      }

   //Override other getText if you need


{code}

Please correct me. Thanks for the help

> Override TextProvider doesnot work in struts 2.5.12
> ---------------------------------------------------
>
>                 Key: WW-4830
>                 URL: https://issues.apache.org/jira/browse/WW-4830
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.5.12
>            Reporter: Alireza Fattahi
>             Fix For: 2.5.13
>
>
> In struts 2.3 , to override the TextProvider we used below
> {code:xml}
> 	<constant name="struts.xworkTextProvider" value="DefaultTextProvider" />
> 	<bean type="com.opensymphony.xwork2.TextProvider" name="DefaultTextProvider" class=".utils.CustomTextProvider"
scope="default" />
> {code}
> And make CustomTextProvider
> {code}
> public class CustomTextProvider extends DefaultTextProvider{
> public String getText(String key, String defaultValue, List<?> args) {
>         String text = super.getText(key, defaultValue, args);
>         //Do something with the text
>         //and return it
>     }
>  //other getText methods can be override too
> }
> {code}
> This seems not to be worked at Struts 2.15.2. 
> To make some test, I remove my bean from* strust.xml* and put some break points in *DefaultTextProvider
*the *getText *of this class is not called, however I find that the *TextProviderSupport **getText
*method is called. 
> Should we override other classes ?!



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

Mime
View raw message