You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/09/09 00:44:33 UTC
svn commit: r995275 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java
Author: jakobk
Date: Wed Sep 8 22:44:33 2010
New Revision: 995275
URL: http://svn.apache.org/viewvc?rev=995275&view=rev
Log:
MYFACES-2912 Wrong JNDI Name for Method Resource Injections (Thanks to Gurkan Erdogdu for this patch)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java?rev=995275&r1=995274&r2=995275&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java Wed Sep 8 22:44:33 2010
@@ -159,7 +159,7 @@ public class ResourceAnnotationLifecycle
{
// TODO local or global JNDI
lookedupResource =
- context.lookup(JAVA_COMP_ENV + instance.getClass().getName() + "/" + method.getName().substring(3));
+ context.lookup(JAVA_COMP_ENV + instance.getClass().getName() + "/" + getFieldName(method));
}
boolean accessibility = method.isAccessible();
@@ -167,4 +167,25 @@ public class ResourceAnnotationLifecycle
method.invoke(instance, lookedupResource);
method.setAccessible(accessibility);
}
+
+ /**
+ * Returns the field name for the given Method.
+ * E.g. setName() will be "name".
+ *
+ * @param setter the setter method
+ * @return the field name of the given setter method
+ */
+ protected static String getFieldName(Method setter)
+ {
+ StringBuilder name = new StringBuilder(setter.getName());
+
+ // remove 'set'
+ name.delete(0, 3);
+
+ // lowercase first char
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+
+ return name.toString();
+ }
+
}