You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "chad davis (JIRA)" <ji...@apache.org> on 2012/10/18 22:36:03 UTC

[jira] [Created] (WW-3905) The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI

chad davis created WW-3905:
------------------------------

             Summary: The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI 
                 Key: WW-3905
                 URL: https://issues.apache.org/jira/browse/WW-3905
             Project: Struts 2
          Issue Type: Bug
          Components: Core Actions
    Affects Versions: 2.3.4.1
            Reporter: chad davis
             Fix For: 2.3.6


The injection of the TextProvider into ActionSupport occurs via a lazy initialization in the getTextProvider() method.  This method obtains the TextProvider from a factory that has the implementation injected into it via  the core di mechanism.  The problem with this is that ActionSupport programmatically does the injection using it's reference to the core ContainerImpl.  This makes it impossible to use the Spring plugin's SpringObjectFactory to manage this TextProvider.    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (WW-3905) The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13485709#comment-13485709 ] 

Lukasz Lenart commented on WW-3905:
-----------------------------------

It'll will not work :\ ObjectFactory can create concrete class not interfaces :/ Need to find a better solution.
                
> The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI 
> ------------------------------------------------------------------------------------------------
>
>                 Key: WW-3905
>                 URL: https://issues.apache.org/jira/browse/WW-3905
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.4.1
>            Reporter: chad davis
>              Labels: ActionSupport, DependencyInjection, TextProvider
>             Fix For: 2.3.7
>
>
> The injection of the TextProvider into ActionSupport occurs via a lazy initialization in the getTextProvider() method.  This method obtains the TextProvider from a factory that has the implementation injected into it via  the core di mechanism.  The problem with this is that ActionSupport programmatically does the injection using it's reference to the core ContainerImpl.  This makes it impossible to use the Spring plugin's SpringObjectFactory to manage this TextProvider.    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (WW-3905) The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13485709#comment-13485709 ] 

Lukasz Lenart edited comment on WW-3905 at 10/28/12 8:55 PM:
-------------------------------------------------------------

It'll will not work :\ ObjectFactory can create concrete class not interfaces :/ Need to find a better solution.
                
      was (Author: lukaszlenart):
    It'll will not work :\ ObjectFactory cannot create concrete class not interfaces :/ Need to find a better solution.
                  
> The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI 
> ------------------------------------------------------------------------------------------------
>
>                 Key: WW-3905
>                 URL: https://issues.apache.org/jira/browse/WW-3905
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.4.1
>            Reporter: chad davis
>              Labels: ActionSupport, DependencyInjection, TextProvider
>             Fix For: 2.3.7
>
>
> The injection of the TextProvider into ActionSupport occurs via a lazy initialization in the getTextProvider() method.  This method obtains the TextProvider from a factory that has the implementation injected into it via  the core di mechanism.  The problem with this is that ActionSupport programmatically does the injection using it's reference to the core ContainerImpl.  This makes it impossible to use the Spring plugin's SpringObjectFactory to manage this TextProvider.    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (WW-3905) The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13479646#comment-13479646 ] 

Lukasz Lenart edited comment on WW-3905 at 10/19/12 5:57 AM:
-------------------------------------------------------------

My solution is like this, you can test it by overriding getTextProvider() in your actions

{code:java}
protected TextProvider getTextProvider() {
    if (textProvider == null) {
        ObjectFactory objectFactory = ActionContext.getContext().getInstance(ObjectFactory.class);
        if (objectFactory == null) {
            TextProviderFactory tpf = new TextProviderFactory();
            textProvider = tpf.createInstance(getClass(), this);
        } else {
            try {
                Map<String, Object> context = Collections.emptyMap();
                textProvider = (TextProvider) objectFactory.buildBean(TextProvider.class, context);
            } catch (Exception e) {
                throw new ConfigurationException("Cannot create TextProvider with ObjectFactory!", e);
            }
        }
    }
    return textProvider;
}
{code}

The only problem is this will work only with actions, in other places a different instance of TextProvider will be used.
                
      was (Author: lukaszlenart):
    My solution is like this, you can test it by overriding getTextProvider() in your actions

{code:java}
protected TextProvider getTextProvider() {
    if (textProvider == null) {
        TextProviderFactory tpf;
        ObjectFactory objectFactory = ActionContext.getContext().getInstance(ObjectFactory.class);
        if (objectFactory == null) {
            tpf = new TextProviderFactory();
            textProvider = tpf.createInstance(getClass(), this);
        } else {
            try {
                Map<String, Object> context = Collections.emptyMap();
                textProvider = (TextProvider) objectFactory.buildBean(TextProvider.class, context);
            } catch (Exception e) {
                throw new ConfigurationException("Cannot create TextProvider with ObjectFactory!", e);
            }
        }
    }
    return textProvider;
}
{code}
                  
> The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI 
> ------------------------------------------------------------------------------------------------
>
>                 Key: WW-3905
>                 URL: https://issues.apache.org/jira/browse/WW-3905
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.4.1
>            Reporter: chad davis
>              Labels: ActionSupport, DependencyInjection, TextProvider
>             Fix For: 2.3.6
>
>
> The injection of the TextProvider into ActionSupport occurs via a lazy initialization in the getTextProvider() method.  This method obtains the TextProvider from a factory that has the implementation injected into it via  the core di mechanism.  The problem with this is that ActionSupport programmatically does the injection using it's reference to the core ContainerImpl.  This makes it impossible to use the Spring plugin's SpringObjectFactory to manage this TextProvider.    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (WW-3905) The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13479646#comment-13479646 ] 

Lukasz Lenart commented on WW-3905:
-----------------------------------

My solution is like this, you can test it by overriding getTextProvider() in your actions

{code:java}
protected TextProvider getTextProvider() {
    if (textProvider == null) {
        TextProviderFactory tpf;
        ObjectFactory objectFactory = ActionContext.getContext().getInstance(ObjectFactory.class);
        if (objectFactory == null) {
            tpf = new TextProviderFactory();
            textProvider = tpf.createInstance(getClass(), this);
        } else {
            try {
                Map<String, Object> context = Collections.emptyMap();
                textProvider = (TextProvider) objectFactory.buildBean(TextProvider.class, context);
            } catch (Exception e) {
                throw new ConfigurationException("Cannot create TextProvider with ObjectFactory!", e);
            }
        }
    }
    return textProvider;
}
{code}
                
> The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI 
> ------------------------------------------------------------------------------------------------
>
>                 Key: WW-3905
>                 URL: https://issues.apache.org/jira/browse/WW-3905
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.4.1
>            Reporter: chad davis
>              Labels: ActionSupport, DependencyInjection, TextProvider
>             Fix For: 2.3.6
>
>
> The injection of the TextProvider into ActionSupport occurs via a lazy initialization in the getTextProvider() method.  This method obtains the TextProvider from a factory that has the implementation injected into it via  the core di mechanism.  The problem with this is that ActionSupport programmatically does the injection using it's reference to the core ContainerImpl.  This makes it impossible to use the Spring plugin's SpringObjectFactory to manage this TextProvider.    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (WW-3905) The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI

Posted by "chad davis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13480078#comment-13480078 ] 

chad davis commented on WW-3905:
--------------------------------

So, if we do it this way, which looks great to me . . . then how do I configure the DI to inject the current Action.  The TextProviderSupport needs contextual stuff from the current action, clazz and localeProvider.  Also, my CustomTextProviderSupport use case requires the action, as another type of provider similar to localeProvider ( a "component" provider that provides access to the component from our system related to the current request ).  So, wiring these current action bits into the textSupport still eludes me.  

With this proposed fix, I would hope to enable all of this wiring as injections into my CustomTextSupport configured in my DI meta data.  But I don't know how it works to reference the "current action" from this pre-runtime situation.  Perhaps this is the wrong approach . . . perhaps I should be writing my CustomTextSupport so that it know's how to find it's resources in the ActionContext or ValueStack, similar to how you obtain the ObjectFactory with the getInstance method above.  Can I do something like this to obtain the current Action? 
                
> The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI 
> ------------------------------------------------------------------------------------------------
>
>                 Key: WW-3905
>                 URL: https://issues.apache.org/jira/browse/WW-3905
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.4.1
>            Reporter: chad davis
>              Labels: ActionSupport, DependencyInjection, TextProvider
>             Fix For: 2.3.6
>
>
> The injection of the TextProvider into ActionSupport occurs via a lazy initialization in the getTextProvider() method.  This method obtains the TextProvider from a factory that has the implementation injected into it via  the core di mechanism.  The problem with this is that ActionSupport programmatically does the injection using it's reference to the core ContainerImpl.  This makes it impossible to use the Spring plugin's SpringObjectFactory to manage this TextProvider.    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (WW-3905) The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13481275#comment-13481275 ] 

Lukasz Lenart commented on WW-3905:
-----------------------------------

I'm not sure if I follow you, using ActionContext isn't the best practise as thus tides your code with framework internals and can be hard to test.

You can use dedicated interceptor (interceptors are created by ObjectFactory as well) and used it to inject your CustomTextProvider onto action. The interceptor has access to request and action. 
                
> The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI 
> ------------------------------------------------------------------------------------------------
>
>                 Key: WW-3905
>                 URL: https://issues.apache.org/jira/browse/WW-3905
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.4.1
>            Reporter: chad davis
>              Labels: ActionSupport, DependencyInjection, TextProvider
>             Fix For: 2.3.6
>
>
> The injection of the TextProvider into ActionSupport occurs via a lazy initialization in the getTextProvider() method.  This method obtains the TextProvider from a factory that has the implementation injected into it via  the core di mechanism.  The problem with this is that ActionSupport programmatically does the injection using it's reference to the core ContainerImpl.  This makes it impossible to use the Spring plugin's SpringObjectFactory to manage this TextProvider.    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (WW-3905) The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13485709#comment-13485709 ] 

Lukasz Lenart edited comment on WW-3905 at 10/28/12 8:55 PM:
-------------------------------------------------------------

It'll will not work :\ ObjectFactory cannot create concrete class not interfaces :/ Need to find a better solution.
                
      was (Author: lukaszlenart):
    It'll will not work :\ ObjectFactory can create concrete class not interfaces :/ Need to find a better solution.
                  
> The TextProvider injection in ActionSupport isn't quite integrated into the framework's core DI 
> ------------------------------------------------------------------------------------------------
>
>                 Key: WW-3905
>                 URL: https://issues.apache.org/jira/browse/WW-3905
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.4.1
>            Reporter: chad davis
>              Labels: ActionSupport, DependencyInjection, TextProvider
>             Fix For: 2.3.7
>
>
> The injection of the TextProvider into ActionSupport occurs via a lazy initialization in the getTextProvider() method.  This method obtains the TextProvider from a factory that has the implementation injected into it via  the core di mechanism.  The problem with this is that ActionSupport programmatically does the injection using it's reference to the core ContainerImpl.  This makes it impossible to use the Spring plugin's SpringObjectFactory to manage this TextProvider.    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira