You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ray Shi <ra...@gmail.com> on 2006/09/20 03:42:15 UTC
[Jelly] Retrieving properties of Java beans in scripts
Hi there,
In the Java code, if I creat an Order bean instancen, and set it to the
variable 'order' in the Jelly context as showed in the folllowing code
snippet,
…
myJellyContext.setVariable("order", order);
…
myScript.run(myJellyContext, output);
...
Then in the Jelly script, I would expect the jelly:core expr element <j:expr
value='${order.customer.name}'/> would return "Bob Smith" which is the value
of the nested 'name' property.
However with the current Jelly implementation, it returns a null value.
So how do I access the properties of Java beans added into the Jelly context
from within the Jelly scripts?
Thanks in advance
Ray
Re: [Jelly] Retrieving properties of Java beans in scripts
Posted by Paul Libbrecht <pa...@activemath.org>.
Ray,
In principle all this is delegated to Jexl which delegates this to
beanutils. I think your expectation is correct but there may either a
half-correct usage of beanutils or a half-bean-conformance in your
objects. Have you tried to make it using method calls (which is all it
boils down to at the end) ?
${order.getCustomer().getName()}
paul
Ray Shi wrote:
> Hi there,
>
> In the Java code, if I creat an Order bean instancen, and set it to the
> variable 'order' in the Jelly context as showed in the folllowing code
> snippet,
> …
> myJellyContext.setVariable("order", order);
> …
> myScript.run(myJellyContext, output);
> ...
>
> Then in the Jelly script, I would expect the jelly:core expr element
> <j:expr
> value='${order.customer.name}'/> would return "Bob Smith" which is the
> value
> of the nested 'name' property.
>
> However with the current Jelly implementation, it returns a null value.
>
> So how do I access the properties of Java beans added into the Jelly
> context
> from within the Jelly scripts?
>
>
> Thanks in advance
> Ray
>
Re: [Jelly] Retrieving properties of Java beans in scripts
Posted by Ray Shi <ra...@gmail.com>.
Hi Dion & Paul,
It was indeed a problem with one of my bean classes - it has a property
defined as a public instance field without any accessors.
Thanks for throwing lights to the right direction.
Ray
On 20/09/06, Dion Gillard <di...@gmail.com> wrote:
>
> Ray,
>
> this should work as described and there are tests to check that it
> does. Is there something unusual with your bean properties?
>
> Could you post the relevant classes?
>
> On 9/20/06, Ray Shi <ra...@gmail.com> wrote:
> > Hi there,
> >
> > In the Java code, if I creat an Order bean instancen, and set it to the
> > variable 'order' in the Jelly context as showed in the folllowing code
> > snippet,
> > …
> > myJellyContext.setVariable("order", order);
> > …
> > myScript.run(myJellyContext, output);
> > ...
> >
> > Then in the Jelly script, I would expect the jelly:core expr element
> <j:expr
> > value='${order.customer.name}'/> would return "Bob Smith" which is the
> value
> > of the nested 'name' property.
> >
> > However with the current Jelly implementation, it returns a null value.
> >
> > So how do I access the properties of Java beans added into the Jelly
> context
> > from within the Jelly scripts?
> >
> >
> > Thanks in advance
> > Ray
> >
> >
>
>
> --
> http://www.multitask.com.au/people/dion/
> Rule of Acquisition #91: Hear all, trust nothing.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
Re: [Jelly] Retrieving properties of Java beans in scripts
Posted by Dion Gillard <di...@gmail.com>.
Ray,
this should work as described and there are tests to check that it
does. Is there something unusual with your bean properties?
Could you post the relevant classes?
On 9/20/06, Ray Shi <ra...@gmail.com> wrote:
> Hi there,
>
> In the Java code, if I creat an Order bean instancen, and set it to the
> variable 'order' in the Jelly context as showed in the folllowing code
> snippet,
> …
> myJellyContext.setVariable("order", order);
> …
> myScript.run(myJellyContext, output);
> ...
>
> Then in the Jelly script, I would expect the jelly:core expr element <j:expr
> value='${order.customer.name}'/> would return "Bob Smith" which is the value
> of the nested 'name' property.
>
> However with the current Jelly implementation, it returns a null value.
>
> So how do I access the properties of Java beans added into the Jelly context
> from within the Jelly scripts?
>
>
> Thanks in advance
> Ray
>
>
--
http://www.multitask.com.au/people/dion/
Rule of Acquisition #91: Hear all, trust nothing.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org