Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
[JAVASERVERFACES-22] managed-bean properties pointing at non-managed beans fail Created: 27/Jul/04 Updated: 26/Jun/12 Resolved: 19/Apr/06 Status: Project: Component/s: Affects Version/s: Fix Version/s: Closed javaserverfaces None 1.1 Type: Reporter: Resolution: Labels: Remaining Estimate: Time Spent: Original Estimate: Environment: Bug adamwiner Fixed None Not Specified Issuezilla Id: 22 1.1_01 Priority: Assignee: Votes: Critical rogerk 0 Not Specified Not Specified Operating System: All Platform: All Description I'm trying to set up a managed bean that points at non-managed bean: <managed-bean> <managed-bean-name>foo</managed-bean-name> <managed-bean-class>my.Foo</managed-bean-class> <managed-bean-scope>request<managed-bean-scope> <managed-property> <property-name>object</property-name> <value># {myObject} </value> </managed-property> </managed-bean> I've used a plugin VariableResolver that guarantees that "myObject" is available. But com.sun.faces.config.ManagedBeanFactory.getScopeForSingleExpression() throws an exception, because it doesn't know what scope "myObject" is in. When confronted with an object it doesn't know, ManagedBeanFactory must assume (or hope) for the best, not throw an exception. This code must only detect provable errors, not potential errors. The simple fix is to replace: // we are referring to a bean that doesn't exist in the // configuration file. Object[] obj = new Object[1]; obj[0] = (null != firstSegment[0]) ? firstSegment[0] : value; throw new EvaluationException( Util.getExceptionMessageString( Util.NAMED_OBJECT_NOT_FOUND_ERROR_MESSAGE_ID, obj)); with just "return RIConstants.APPLICATION;" Comments Comment by rogerk [ 28/Jul/04 ] I'll take this one.. Comment by jayashri [ 28/Jul/04 ] To be addressed in 1.1_01 Comment by rogerk [ 30/Jul/04 ] Here's the patch: Summary: Referencing non managed beans in config file throws exception. Author: Adam Winer Test: Roger Kitain https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=22 M src/com/sun/faces/config/ManagedBeanFactory.java gracefully handle non-managed beans by assigning a scope. M test/com/sun/faces/config/ConfigFileTestCase.java added non managed bean test case A test/com/sun/faces/config/NonManagedBean.java simple bean referenced as a managed property M test/com/sun/faces/config/SimpleBean.java added accessor methods for nonManagedBean M web/test/WEB-INF/faces-config.xml added managed-property referencing the non managed bean Index: ManagedBeanFactory.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/config/ManagedBeanFactory.java,v retrieving revision 1.23 diff -u -r1.23 ManagedBeanFactory.java — ManagedBeanFactory.java 10 May 2004 19:56:04 -0000 1.23 +++ ManagedBeanFactory.java 30 Jul 2004 13:38:55 -0000 @@ -992,12 +992,8 @@ } else { // we are referring to a bean that doesn't exist in the - // configuration file. - Object[] obj = new Object[1]; - obj[0] = (null != firstSegment[0]) ? firstSegment[0] : value; - throw new EvaluationException( - Util.getExceptionMessageString( Util.NAMED_OBJECT_NOT_FOUND_ERROR_MESSAGE_ID, obj)); + // configuration file. Give it a wide scope... + valueScope = RIConstants.APPLICATION; } } return valueScope; Index: ConfigFileTestCase.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/config/ConfigFileTestCase.java,v retrieving revision 1.63 diff -u -r1.63 ConfigFileTestCase.java — ConfigFileTestCase.java 26 Jul 2004 21:12:45 -0000 1.63 +++ ConfigFileTestCase.java 30 Jul 2004 13:40:00 -0000 @@ -298,7 +298,9 @@ m[i].getName().equals("setIntProperty") || m[i].getName().equals("getIntProperty") || m[i].getName().equals("getTrueValue") || m[i].getName().equals("getFalseValue")); + m[i].getName().equals("getFalseValue") || + m[i].getName().equals("setNonManagedBean") || + m[i].getName().equals("getNonManagedBean")); if (m[i].getName().equals("getSimpleProperty")) { Object args[] = null; Object value = m[i].invoke(bean, args); @@ -639,4 +641,38 @@ assertTrue(bean.getCustomerBean() instanceof com.sun.faces.CustomerBean); } + + public void testNonManagedBeans() throws Exception { + parseConfig("WEB-INF/faces-config.xml", + config.getServletContext()); + + ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder.getFactory(+ FactoryFinder.APPLICATION_FACTORY); + ApplicationImpl application = (ApplicationImpl) aFactory.getApplication(); + + ApplicationAssociate associate = ApplicationAssociate.getInstance(getFacesContext().getExternalContext()); + Object bean = + associate.createAndMaybeStoreManagedBeans(getFacesContext(), + "SimpleBean"); + + // Assert the methods exist on the created bean.. + try { + Class c = bean.getClass(); + Method m[] = c.getDeclaredMethods(); + int methodCnt = 0; + for (int i = 0; i < m.length; i++) { + if (m[i].getName().equals("setNonManagedBean")) { + methodCnt++; + } + if (m[i].getName().equals("getNonManagedBean")) { + methodCnt++; + } +} + assertEquals("non managed bean methods not found", methodCnt, 2); + } catch (Throwable t) { + assertTrue(false); + } + +} + } cvs server: NonManagedBean.java is a new entry, no comparison available Index: SimpleBean.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/config/SimpleBean.java,v retrieving revision 1.7 diff -u -r1.7 SimpleBean.java — SimpleBean.java 12 May 2004 18:31:26 -0000 1.7 +++ SimpleBean.java 30 Jul 2004 13:40:00 -0000 @@ -46,4 +46,12 @@ public boolean getFalseValue() { return false; } + + private NonManagedBean nonManagedBean = null; + public NonManagedBean getNonManagedBean() { + return nonManagedBean; + } + public void setNonManagedBean(NonManagedBean nmb) { + nonManagedBean = nmb; + } } Index: faces-config.xml =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/web/test/WEB-INF/faces-config.xml,v retrieving revision 1.22 diff -u -r1.22 faces-config.xml — faces-config.xml 11 May 2004 19:27:08 -0000 1.22 +++ faces-config.xml 30 Jul 2004 13:41:54 -0000 @@ -337,6 +337,10 @@ <property-name>simpleProperty</property-name> <value>Bobby Orr</value> </managed-property> + <managed-property> + <property-name>nonManagedBean</property-name> + <value># {nonManagedBean} </value> + </managed-property> </managed-bean> New Non Managed Bean: /* Copyright 2004 Sun Microsystems, Inc. All rights reserved. SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.sun.faces.config; public class NonManagedBean { public NonManagedBean() {}; } Comment by rogerk [ 04/Aug/04 ] fixed. Comment by Manfred Riem [ 06/Feb/12 ] Closing issue out Generated at Wed May 10 15:28:32 UTC 2017 using JIRA 6.2.3#6260sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.