Re: Does FM support varargs or arrays in method calls?

Attila Szegedi <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
We've added vararg handling to 2.4 (which is not yet released).  
There's currently no vararg handling in 2.3. Can you try using 2.4?  
You can grab the latest 2.4 build from here:

- go to <http://freemarker.org:8085/browse/FM-TRUNK/latest>
- click "Artifacts" tab
- download the freemarker.jar behind the "Library" link

Failing that, I can backport vararg handling to 2.3.x branch.

Attila.

On 2007.12.05., at 23:17, Newman, John W wrote:

> 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

Attila.

--
home: http://www.szegedi.org
weblog: http://constc.blogspot.com




-------------------------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.