You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ugo Cei <u....@cbim.it> on 2003/08/01 00:31:47 UTC
Garbage or The Quest for the Perfect Template Language
These days I'm banging my head against the limitations of template
languages. I've tried XSP and it's not in any way limited, but it has
its share of problems (difficult to debug and offers too many ways to
shoot oneself in the foot), JXTemplate{Transformer,Generator} (no way to
call methods on context objects, no decent arithmetic) and Velocity
(stream based, no FP math).
I've read about Garbage but I haven't tried it. It looks promising
though, and I hope that Pier is going to really push it forward when he
finds some free time.
There are a couple of things that a good template language should do.
Consider the following requirement: given a model consisting of a list
of floating point numbers, print all of them, localizing their
represantion according to some locale, then compute and display their sum.
You can format the numbers using Velocity, but you must explicitly pass
an instance of DecimalFormat to the view. I'd like the template language
to have built-in support for the localization of numbers, currencies and
dates.
You cannot apparently sum the numbers using Velocity. I was startled to
discover, the other day, that if you try to sum doubles with Velocity,
it will instead concatenate their string representations! I hope it was
a mistake of mine, because it would really be dumb if it were indeed the
case. Anyway, whatever the language we come up with, it should be able
to correctly perform floating point arithmetic.
This is my plea for the perfect template language and I hope that,
whoever implements it, considers adding these features.
Ugo
Re: Garbage or The Quest for the Perfect Template Language
Posted by Ugo Cei <u....@cbim.it>.
Christopher Oliver wrote:
> What was your expression?
``registrazione/dataCompilazione''
where "registrazione" is an instance of
public class Registrazione {
private java.util.Date dataCompilazione;
public java.util.Date getDataCompilazione() {
return dataCompilazione;
}
}
Actually, at runtime the "dataCompilazione" member points to an instance
of "java.sql.Timestamp" (implements java.util.Date).
If I just do <jx:out value="#{registrazione/dataCompilazione}"/>, I get
the default string representation of the date, so by itself the
expression does evaluate to a Date.
> By the way JXTemplateGenerator adds the capability to call Java
> constructors to Jexl, so you can also do this:
>
> <jx:out
> value='${java.text.SimpleDateFormat("dd/MM/yyyy").format(someDate)}'/>
I'll try this option tomorrow, if I can't solve my problem with XPath.
Ugo
Re: Garbage or The Quest for the Perfect Template Language
Posted by Nicola Ken Barozzi <ni...@apache.org>.
Ugo Cei wrote, On 07/08/2003 9.28:
> Christopher Oliver wrote:
>
>> In general, I think you're right, though, JXTemplate generator
>> requires additional tags to support Number, Date, and Message
>> formatting. JSTL has such tags. If I have time I'll try to add them.
>
> Nice. After having tried Velocity, MHO is that it sucks,
It all depends on what you have to do with it. I'm using it in another
project and it rocks. Let's not overgeneralize, please, as each tool has
its place.
> so let's
> enhance JXTemplate until it's the perfect template language for Cocoon.
> I'll be glad to help you in this effort as soon as I come back from my
> vacations (that is, from tomorrow until Sep. 1st).
Why not Jelly?
I mean, it can reuse most taglibs, from Ant and JSTL, it's easy to add
tasks, is XML-based (hence validates)... really, why not?
--
Nicola Ken Barozzi nicolaken@apache.org
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------
Re: Garbage or The Quest for the Perfect Template Language
Posted by Christopher Oliver <re...@verizon.net>.
As a workaround, both of these work for me:
#{format(java.text.SimpleDateFormat.new('MM/dd/yy',
java.util.Locale.new('ITALIAN')), java.util.Date.new())}
${java.text.SimpleDateFormat("MM/dd/yy",
java.util.Locale("ITALIAN")).format(java.util.Date())}
Ugo Cei wrote:
> Christopher Oliver wrote:
>
>> In general, I think you're right, though, JXTemplate generator
>> requires additional tags to support Number, Date, and Message
>> formatting. JSTL has such tags. If I have time I'll try to add them.
>
>
> Nice. After having tried Velocity, MHO is that it sucks, so let's
> enhance JXTemplate until it's the perfect template language for
> Cocoon. I'll be glad to help you in this effort as soon as I come back
> from my vacations (that is, from tomorrow until Sep. 1st).
>
> Ugo
>
Re: Garbage or The Quest for the Perfect Template Language
Posted by Ugo Cei <u....@cbim.it>.
Christopher Oliver wrote:
> In general, I think you're right, though, JXTemplate generator requires
> additional tags to support Number, Date, and Message formatting. JSTL
> has such tags. If I have time I'll try to add them.
Nice. After having tried Velocity, MHO is that it sucks, so let's
enhance JXTemplate until it's the perfect template language for Cocoon.
I'll be glad to help you in this effort as soon as I come back from my
vacations (that is, from tomorrow until Sep. 1st).
Ugo
--
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it
Re: Garbage or The Quest for the Perfect Template Language
Posted by Christopher Oliver <re...@verizon.net>.
That's a problem with JXTemplateGenerator: it returns a raw
java.lang.Class object from "java.util.Locale" which doesn't have a
property "ITALIAN". I'll try to fix that so it returns a wrapped Class
object that shows static fields as properties as in JavaScript.
In general, I think you're right, though, JXTemplate generator requires
additional tags to support Number, Date, and Message formatting. JSTL
has such tags. If I have time I'll try to add them.
Regards,
Chris
Ugo Cei wrote:
> Christopher Oliver wrote:
>
>> By the way JXTemplateGenerator adds the capability to call Java
>> constructors to Jexl, so you can also do this:
>>
>> <jx:out
>> value='${java.text.SimpleDateFormat("dd/MM/yyyy").format(someDate)}'/>
>
>
> OK, this works:
>
> ${java.text.SimpleDateFormat("dd/MM/yyyy").format(date)}
>
> But this does not:
>
> ${java.text.SimpleDateFormat("dd/MM/yyyy",java.util.Locale.ITALIAN).format(date)}
>
>
> and gives the following error:
>
> The choice of Java constructor java.text.SimpleDateFormat matching
> JavaScript argument types (string,null) is ambiguous; candidate
> constructors are: (java.lang.String,java.text.DateFormatSymbols),
> (java.lang.String,java.util.Locale)
>
> Problem with static members?
>
> Ugo
>
Re: Garbage or The Quest for the Perfect Template Language
Posted by Ugo Cei <u....@cbim.it>.
Christopher Oliver wrote:
> By the way JXTemplateGenerator adds the capability to call Java
> constructors to Jexl, so you can also do this:
>
> <jx:out
> value='${java.text.SimpleDateFormat("dd/MM/yyyy").format(someDate)}'/>
OK, this works:
${java.text.SimpleDateFormat("dd/MM/yyyy").format(date)}
But this does not:
${java.text.SimpleDateFormat("dd/MM/yyyy",java.util.Locale.ITALIAN).format(date)}
and gives the following error:
The choice of Java constructor java.text.SimpleDateFormat matching
JavaScript argument types (string,null) is ambiguous; candidate
constructors are: (java.lang.String,java.text.DateFormatSymbols),
(java.lang.String,java.util.Locale)
Problem with static members?
Ugo
--
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it
Re: Garbage or The Quest for the Perfect Template Language
Posted by Christopher Oliver <re...@verizon.net>.
Ugo Cei wrote:
> Ugo Cei wrote:
>
>> org.apache.commons.jxpath.JXPathException: Cannot invoke public final
>> java.lang.String java.text.Format.format(java.lang.Object); Cannot
>> format given Object as a Date
>
>
> More info: printing
> #{getClass(myXPathExpressionThatShouldPointToADate)} yelds:
>
> class org.apache.commons.jxpath.ri.EvalContext$SimpleNodeSet
>
> Baffled,
>
> Ugo
>
What was your expression?
By the way JXTemplateGenerator adds the capability to call Java
constructors to Jexl, so you can also do this:
<jx:out
value='${java.text.SimpleDateFormat("dd/MM/yyyy").format(someDate)}'/>
As in JavaScript, classes in packages other than "java" are under the
"Packages" property, for example:
<jx:out
value='${Packages.com.xyz.text.MyClass(blah).someMethod(blah)}'/> is
equivalent to:
new com.xyz.myClass(blah).someMethod(blah);
Chris
Re: Garbage or The Quest for the Perfect Template Language
Posted by Ugo Cei <u....@cbim.it>.
Ugo Cei wrote:
> org.apache.commons.jxpath.JXPathException: Cannot invoke public final
> java.lang.String java.text.Format.format(java.lang.Object); Cannot
> format given Object as a Date
More info: printing #{getClass(myXPathExpressionThatShouldPointToADate)}
yelds:
class org.apache.commons.jxpath.ri.EvalContext$SimpleNodeSet
Baffled,
Ugo
--
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it
Re: Garbage or The Quest for the Perfect Template Language
Posted by Ugo Cei <u....@cbim.it>.
Nicola Ken Barozzi wrote:
> Seems like it should be
>
> format(java.text.SimpleDateFormat.new("dd/MM/yyyy"), someDate)
Close but no cigar:
org.apache.commons.jxpath.JXPathException: Cannot invoke public final
java.lang.String java.text.Format.format(java.lang.Object); Cannot
format given Object as a Date
:-(
Ugo
--
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it
Re: Garbage or The Quest for the Perfect Template Language
Posted by Nicola Ken Barozzi <ni...@apache.org>.
Ugo Cei wrote, On 05/08/2003 16.50:
> Sylvain Wallez wrote:
>
>> Checkout the last paragraph of JXPath's PackageFunctions description
>> [1], this may be what you're looking for : the whole classpath is
>> accessible through fully-qualified names.
>>
>> [1]
>> http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/PackageFunctions.html
>>
>> Sylvain
>
>
> I've read it and tried to do the following:
>
> <jx:out
> value='#{java.text.SimpleDateFormat.format(java.text.SimpleDateFormat.new("dd/MM/yyyy"),
> someDate)}'/>
>
> where ``someDate'' evaluates to an instance of java.util.Date, but I get
> the following error:
>
> org.apache.commons.jxpath.JXPathException: Undefined function:
> java.text.SimpleDateFormat.format
In
http://jakarta.apache.org/commons/jxpath/users-guide.html
At
http://jakarta.apache.org/commons/jxpath/users-guide.html#Extension%20Functions
Seems like it should be
format(java.text.SimpleDateFormat.new("dd/MM/yyyy"), someDate)
Usually when I use jxpath I use this though, it makes it much easier:
http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/PackageFunctions.html
> Ugo (still searching for the perfect template language)
--
Nicola Ken Barozzi nicolaken@apache.org
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------
Re: Garbage or The Quest for the Perfect Template Language
Posted by Ugo Cei <u....@cbim.it>.
Sylvain Wallez wrote:
> Checkout the last paragraph of JXPath's PackageFunctions description
> [1], this may be what you're looking for : the whole classpath is
> accessible through fully-qualified names.
>
> [1]
> http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/PackageFunctions.html
>
>
> Sylvain
I've read it and tried to do the following:
<jx:out
value='#{java.text.SimpleDateFormat.format(java.text.SimpleDateFormat.new("dd/MM/yyyy"),
someDate)}'/>
where ``someDate'' evaluates to an instance of java.util.Date, but I get
the following error:
org.apache.commons.jxpath.JXPathException: Undefined function:
java.text.SimpleDateFormat.format
Ugo (still searching for the perfect template language)
--
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it
Re: Garbage or The Quest for the Perfect Template Language
Posted by Ugo Cei <u....@cbim.it>.
Sylvain Wallez wrote:
> Checkout the last paragraph of JXPath's PackageFunctions description
> [1], this may be what you're looking for : the whole classpath is
> accessible through fully-qualified names.
Uh, cool. This deserves to be documented more clearly. I'll try to find
the time to do it.
Ugo
--
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it
Re: Garbage or The Quest for the Perfect Template Language
Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Ugo Cei wrote:
> Christopher Oliver wrote:
>
>> Ugo Cei wrote:
>>
>>> These days I'm banging my head against the limitations of template
>>> languages. I've tried XSP and it's not in any way limited, but it has
>>> its share of problems (difficult to debug and offers too many ways to
>>> shoot oneself in the foot), JXTemplate{Transformer,Generator} (no
>>> way to
>>> call methods on context objects, no decent arithmetic)
>>
>>
>>
>> What exactly is the problem with the arithmetic in Jexl and/or
>> JXPath? What problem did you encounter calling methods? You should be
>> able to with do that with both Jexl and JXPath.
>>
>> Regards,
>>
>> Chris
>
>
> I'll try to come up with an example but I seem to remember having
> problems doing even a simple counter. And WRT calling Java methods, I
> must admit I didn't even try it. Since it's not documented I thought
> it wasn't even implemented ;-).
Checkout the last paragraph of JXPath's PackageFunctions description
[1], this may be what you're looking for : the whole classpath is
accessible through fully-qualified names.
[1]
http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/PackageFunctions.html
Sylvain
--
Sylvain Wallez Anyware Technologies
http://www.apache.org/~sylvain http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance - http://www.orixo.com
Re: Garbage or The Quest for the Perfect Template Language
Posted by Ugo Cei <u....@cbim.it>.
Christopher Oliver wrote:
> Ugo Cei wrote:
>
>> These days I'm banging my head against the limitations of template
>> languages. I've tried XSP and it's not in any way limited, but it has
>> its share of problems (difficult to debug and offers too many ways to
>> shoot oneself in the foot), JXTemplate{Transformer,Generator} (no way to
>> call methods on context objects, no decent arithmetic)
>
>
> What exactly is the problem with the arithmetic in Jexl and/or JXPath?
> What problem did you encounter calling methods? You should be able to
> with do that with both Jexl and JXPath.
>
> Regards,
>
> Chris
I'll try to come up with an example but I seem to remember having
problems doing even a simple counter. And WRT calling Java methods, I
must admit I didn't even try it. Since it's not documented I thought it
wasn't even implemented ;-).
Ugo
--
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it
Re: Garbage or The Quest for the Perfect Template Language
Posted by Christopher Oliver <re...@verizon.net>.
Ugo Cei wrote:
> These days I'm banging my head against the limitations of template
> languages. I've tried XSP and it's not in any way limited, but it has
> its share of problems (difficult to debug and offers too many ways to
> shoot oneself in the foot), JXTemplate{Transformer,Generator} (no way to
> call methods on context objects, no decent arithmetic)
What exactly is the problem with the arithmetic in Jexl and/or JXPath?
What problem did you encounter calling methods? You should be able to
with do that with both Jexl and JXPath.
Regards,
Chris