Does FM support varargs or arrays in method calls?
"Newman, John W" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <EE3D0D387D01C8498EC1CED489DEAB25377A9F67F5@msxmbxnsprd01.acct.upmchs.net> |
Hi,
This is interesting, I might be in trouble here - hopefully I'm just missing something. Consider this,
class WrappedObject {
public <E extends Entity> java.util.List<E> findByNamedQuery(Class<E> entityClass,
String query, Object... queryParams) {
return entityManager.findByNamedQuery(entityClass, query, queryParams);
}
}
class EntityManager {
public <E extends Entity> java.util.List<E> findByNamedQuery(Class<E> entityClass,
String query, Object... queryParams) {
// do hibernate stuff here
}
}
[#assign results = wrappedObject.findByNamedQuery(${class}, "findByFirstAndLastName", ["John", "Smith"]) /]
Should work right?
: freemarker.template.TemplateModelException: No signature of method findByNamedQuery matches (java.lang.Class,java.lang.String,freemarker.ext.beans.SequenceAdapter)
If I forget about the varargs and change the wrapped objects method to use Object[] queryParams, I get the exact same exception. However if I change it to List<Object>, ["John", "Smith"] matches the rule, and the method gets invoked.
That's ok, but I can't change the API of the EntityManager class - we're stuck with varargs there. So,
class WrappedObject {
public <E extends Entity> java.util.List<E> findByNamedQuery(Class<E> entityClass,
String query, List<Object> queryParams) {
return entityManager.findByNamedQuery(entityClass, query, queryParams == null ? queryParams : queryParams.toArray(new Object[queryParams.size()]));
}
}
I really thought that would work. Unfortunately, all it does is pass in 1 parameter to entityManager's method, an Object[] - not Object, Object. Interesting. Any ideas? Is there different syntax for arrays & lists?
Any help is greatly appreciated.
Thanks,
john
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user