You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "David Mansfield (Created) (JIRA)" <ji...@apache.org> on 2012/01/25 20:55:42 UTC

[jira] [Created] (WW-3748) s:bean doesn't allow creation of beans from a spring object factory using the bean's id

s:bean doesn't allow creation of beans from a spring object factory using the bean's id
---------------------------------------------------------------------------------------

                 Key: WW-3748
                 URL: https://issues.apache.org/jira/browse/WW-3748
             Project: Struts 2
          Issue Type: Bug
          Components: Core Actions
    Affects Versions: 2.3.1.1
         Environment: linux, jdk 1.6
            Reporter: David Mansfield
            Priority: Minor


on core/src/main/java/org/apache/struts2/components/Bean.java line 128:

            bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());

Shouldn't this be:

            bean = objectFactory.buildBean(beanName, stack.getContext(), false);

The factory knows how to get a Class from a String as well as anyone, but the "name" is not necessarily a class name when the bean is the id of a spring bean.

This affects s:bean tag.

AFAICT all versions are affected (just checked svn trunk).


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3748) s:bean doesn't allow creation of beans from a spring object factory using the bean's id

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

Lukasz Lenart commented on WW-3748:
-----------------------------------

What about fallback solution:
{code}

        String beanName = findString(name, "name", "Bean name is required. Example: com.acme.FooBean");
        try {
            bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());
        } catch (Exception e) {
            try {
                bean = objectFactory.buildBean(beanName, stack.getContext(), false);
            } catch (Exception e1) {
                LOG.error("Could not instantiate bean", e);
            }
            return false;
        }
{code}
                
> s:bean doesn't allow creation of beans from a spring object factory using the bean's id
> ---------------------------------------------------------------------------------------
>
>                 Key: WW-3748
>                 URL: https://issues.apache.org/jira/browse/WW-3748
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.1.1
>         Environment: linux, jdk 1.6
>            Reporter: David Mansfield
>            Priority: Minor
>             Fix For: 2.3.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> on core/src/main/java/org/apache/struts2/components/Bean.java line 128:
>             bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());
> Shouldn't this be:
>             bean = objectFactory.buildBean(beanName, stack.getContext(), false);
> The factory knows how to get a Class from a String as well as anyone, but the "name" is not necessarily a class name when the bean is the id of a spring bean.
> This affects s:bean tag.
> AFAICT all versions are affected (just checked svn trunk).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3748) s:bean doesn't allow creation of beans from a spring object factory using the bean's id

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

Hudson commented on WW-3748:
----------------------------

Integrated in Struts2 #424 (See [https://builds.apache.org/job/Struts2/424/])
    WW-3748 s:bean shouldn't load class, just delegate that to ObjectFactory (Revision 1295146)

     Result = SUCCESS
lukaszlenart : 
Files : 
* /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Bean.java

                
> s:bean doesn't allow creation of beans from a spring object factory using the bean's id
> ---------------------------------------------------------------------------------------
>
>                 Key: WW-3748
>                 URL: https://issues.apache.org/jira/browse/WW-3748
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.1.1
>         Environment: linux, jdk 1.6
>            Reporter: David Mansfield
>            Assignee: Lukasz Lenart
>            Priority: Minor
>             Fix For: 2.3.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> on core/src/main/java/org/apache/struts2/components/Bean.java line 128:
>             bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());
> Shouldn't this be:
>             bean = objectFactory.buildBean(beanName, stack.getContext(), false);
> The factory knows how to get a Class from a String as well as anyone, but the "name" is not necessarily a class name when the bean is the id of a spring bean.
> This affects s:bean tag.
> AFAICT all versions are affected (just checked svn trunk).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3748) s:bean doesn't allow creation of beans from a spring object factory using the bean's id

Posted by "Lukasz Lenart (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3748?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart updated WW-3748:
------------------------------

    Fix Version/s: 2.3.2
    
> s:bean doesn't allow creation of beans from a spring object factory using the bean's id
> ---------------------------------------------------------------------------------------
>
>                 Key: WW-3748
>                 URL: https://issues.apache.org/jira/browse/WW-3748
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.1.1
>         Environment: linux, jdk 1.6
>            Reporter: David Mansfield
>            Priority: Minor
>             Fix For: 2.3.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> on core/src/main/java/org/apache/struts2/components/Bean.java line 128:
>             bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());
> Shouldn't this be:
>             bean = objectFactory.buildBean(beanName, stack.getContext(), false);
> The factory knows how to get a Class from a String as well as anyone, but the "name" is not necessarily a class name when the bean is the id of a spring bean.
> This affects s:bean tag.
> AFAICT all versions are affected (just checked svn trunk).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Closed] (WW-3748) s:bean doesn't allow creation of beans from a spring object factory using the bean's id

Posted by "Lukasz Lenart (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3748?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart closed WW-3748.
-----------------------------

    Resolution: Fixed
      Assignee: Lukasz Lenart

Right, thanks for patch and clarification!
                
> s:bean doesn't allow creation of beans from a spring object factory using the bean's id
> ---------------------------------------------------------------------------------------
>
>                 Key: WW-3748
>                 URL: https://issues.apache.org/jira/browse/WW-3748
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.1.1
>         Environment: linux, jdk 1.6
>            Reporter: David Mansfield
>            Assignee: Lukasz Lenart
>            Priority: Minor
>             Fix For: 2.3.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> on core/src/main/java/org/apache/struts2/components/Bean.java line 128:
>             bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());
> Shouldn't this be:
>             bean = objectFactory.buildBean(beanName, stack.getContext(), false);
> The factory knows how to get a Class from a String as well as anyone, but the "name" is not necessarily a class name when the bean is the id of a spring bean.
> This affects s:bean tag.
> AFAICT all versions are affected (just checked svn trunk).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3748) s:bean doesn't allow creation of beans from a spring object factory using the bean's id

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

Lukasz Lenart commented on WW-3748:
-----------------------------------

That should work with Spring, Bean.java line 128 will use SpringObjectFactory.buildBean at line 168 and base on class name will instantiate an object. You must use the full class name instead of spring bean id. 
                
> s:bean doesn't allow creation of beans from a spring object factory using the bean's id
> ---------------------------------------------------------------------------------------
>
>                 Key: WW-3748
>                 URL: https://issues.apache.org/jira/browse/WW-3748
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.1.1
>         Environment: linux, jdk 1.6
>            Reporter: David Mansfield
>            Priority: Minor
>             Fix For: 2.3.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> on core/src/main/java/org/apache/struts2/components/Bean.java line 128:
>             bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());
> Shouldn't this be:
>             bean = objectFactory.buildBean(beanName, stack.getContext(), false);
> The factory knows how to get a Class from a String as well as anyone, but the "name" is not necessarily a class name when the bean is the id of a spring bean.
> This affects s:bean tag.
> AFAICT all versions are affected (just checked svn trunk).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3748) s:bean doesn't allow creation of beans from a spring object factory using the bean's id

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

David Mansfield commented on WW-3748:
-------------------------------------

That is exactly what the default ObjectFactory.buildBean(String, Map, boolean) does, so the logic shouldn't be duplicated in Bean.java, IMHO.  But if a subclass overrides (as SpringObjectFactory does) it can to the right thing WRT bean ids.

To summarize, if SpringObjectFactory is not used, the change suggested in the description changes nothing AFAIK.  This is easy to verify looking at ObjectFactory.java

If SpringObjectFactory is used, and the string passed is NOT a bean-id, the change suggested changes nothing.  This is somewhat more difficult, but can be verified looking at SpringObjectFactory.java.  

If SpringObjectFactory is used, and the string passed IS a bean-id, and not a class-name, the code would not be working today, but would be working after the fix.

                
> s:bean doesn't allow creation of beans from a spring object factory using the bean's id
> ---------------------------------------------------------------------------------------
>
>                 Key: WW-3748
>                 URL: https://issues.apache.org/jira/browse/WW-3748
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.1.1
>         Environment: linux, jdk 1.6
>            Reporter: David Mansfield
>            Priority: Minor
>             Fix For: 2.3.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> on core/src/main/java/org/apache/struts2/components/Bean.java line 128:
>             bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());
> Shouldn't this be:
>             bean = objectFactory.buildBean(beanName, stack.getContext(), false);
> The factory knows how to get a Class from a String as well as anyone, but the "name" is not necessarily a class name when the bean is the id of a spring bean.
> This affects s:bean tag.
> AFAICT all versions are affected (just checked svn trunk).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3748) s:bean doesn't allow creation of beans from a spring object factory using the bean's id

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

David Mansfield commented on WW-3748:
-------------------------------------

Yes, but with Spring one doesn't use class names, one uses bean id's.  With my suggested fix, it will work correctly using bean id, and still work correctly in all current situations too.  The rest of struts 2 accepts bean id (e.g. in struts.xml).

                
> s:bean doesn't allow creation of beans from a spring object factory using the bean's id
> ---------------------------------------------------------------------------------------
>
>                 Key: WW-3748
>                 URL: https://issues.apache.org/jira/browse/WW-3748
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.3.1.1
>         Environment: linux, jdk 1.6
>            Reporter: David Mansfield
>            Priority: Minor
>             Fix For: 2.3.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> on core/src/main/java/org/apache/struts2/components/Bean.java line 128:
>             bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName, getClass()), stack.getContext());
> Shouldn't this be:
>             bean = objectFactory.buildBean(beanName, stack.getContext(), false);
> The factory knows how to get a Class from a String as well as anyone, but the "name" is not necessarily a class name when the bean is the id of a spring bean.
> This affects s:bean tag.
> AFAICT all versions are affected (just checked svn trunk).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira