You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by ad...@mrigitech.com on 2004/10/31 20:19:05 UTC
JXTemplate: Expressions not evaluated with mixed attribute content
Hi,
I have a JXTemplate document that uses the <jx:set> element to set a variable
that is the concatenation of an expression and a string literal, this is
equivalent to the example in the JX documentation:
<jx:set var="greeting" value="Hello ${user}"/>
The value of greeting is ${greeting}
When the attribute value is interpreted the expression is not evaluated but the
entire attribute value is treated as a string literal so I get the output 'The
value of greeting is Hello ${user}'. If I switch the order of the expression
and the string literal so that it reads <jx:set var="greeting" value="${user}
Hello"/> the expression is evaluated but the string literal is dropped.
I'm using cocoon-2.1.5.1, is this a known bug or am I just doing something
silly?
Cheers
Adam
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: JXTemplate: Expressions not evaluated with mixed attribute content
Posted by Leszek Gawron <lg...@mobilebox.pl>.
adam@mrigitech.com wrote:
> Hi,
>
> I have a JXTemplate document that uses the <jx:set> element to set a variable
> that is the concatenation of an expression and a string literal, this is
> equivalent to the example in the JX documentation:
>
> <jx:set var="greeting" value="Hello ${user}"/>
> The value of greeting is ${greeting}
>
> When the attribute value is interpreted the expression is not evaluated but the
> entire attribute value is treated as a string literal so I get the output 'The
> value of greeting is Hello ${user}'. If I switch the order of the expression
> and the string literal so that it reads <jx:set var="greeting" value="${user}
> Hello"/> the expression is evaluated but the string literal is dropped.
>
> I'm using cocoon-2.1.5.1, is this a known bug or am I just doing something
> silly?
From what I remember from looking at the code it will only be properly
evaluated if you place your whole expression inside ${} or #{} tag. I do
not think that this is a bug. This implementation allows for variables
being of other types than String. If the value starts with ${ or #{ the
expression inside will be evaluated. If the value starts with anything
else the string will not be parsed at all.
you should use something like:
<jx:set var="a" value="${'Hello '.concat( user )}"/>
or more explicitly:
<jx:set var="a" value="${java.lang.String('Hello ').concat( user )}"/>
I am just guessing that the syntax for JXPath is (might be wrong):
<jx:set var="a" value="#{concat( 'Hello ', user )}
You also cannot use + to concat Strings. + sign can only be used for
numbers. You'll get an exception if you use it for other objects. At
least it was like that last time I checked - the implementation may
differ now as the stable version of Jexl has been released.
lg
--
Leszek Gawron lgawron@mobilebox.pl
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org