You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Benjamin Boksa <ma...@boksa.de> on 2008/08/16 01:21:06 UTC

[2.2] Accessing static methods in JX Templates

Hi List,

at the moment I am working on a simple template to output a list of  
some arbitrary beans including their properties. To do this I would  
like to use PropertyUtil.describe(java.lang.Object bean) [1].

However there seems to be some problem when I try to access  
PropertyUtils within the template (where bean is set by jx:forEach).

    <jx:set var="beanMap" value="$ 
{org.apache.commons.beanutils.PropertyUtils.describe(bean)}"/>
    <jx:out value="${beanMap}"/>

The construct runs without an error but does not output anything. Is  
this the correct behaviour or did I run into a bug?

For now I am using the following workaround (the template is called  
from flowscript)

    importClass(Packages.org.apache.commons.beanutils.PropertyUtils);

    [...]

    cocoon.sendPage("foo", {
       "beanList"	: list,
       "PropertyUtils"	: cocoon.createObject(PropertyUtils)
    });

and accordingly in the template:

    <jx:set var="beanMap" value="${PropertyUtils.describe(bean)}"/>
    <jx:out value="${beanMap}"/>

which outputs a map of the Bean's properties as expected.

As you might imagine I am absolutely not happy with this workaround.  
Is there any better solution or a fix to the issue mentioned above? If  
you need to know more information just let me know. I am looking  
forward to your answers.

Thanks in advance

Benjamin


[1] http://commons.apache.org/beanutils/commons-beanutils-1.7.0/docs/api/org/apache/commons/beanutils/PropertyUtils.html#describe(java.lang.Object)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org