cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bart Molenkamp" <b.molenk...@bizzdesign.nl>
Subject RE: Templating Engine - Next steps?
Date Tue, 02 Nov 2004 08:48:27 GMT


> -----Original Message-----
> From: Leszek Gawron [mailto:lgawron@mobilebox.pl]
> Reinhard Poetz wrote:
> 
> >
> >  - control structures like for/each, if, choose (RP)
> what bugs me is the verbosity of choose/when/otherwise to implement
> if/else semantics. 

I've also been thinking about a simple method for displaying object
instances of different classes. E.g. I get an object from the flow
layer, I need to decide how to format it. Instances of class "A" are
formatted differently than instances from class "B". Now, this could be
done using <jx:choose>, but that doesn't make the code more readable:

<!-- is object instanceof MyClass -->
<jx:when test="object.getClass().getName() == 'com.MyClass'">

Even worse when you want to check if it is instanceof an interface:

<!-- is object instanceof MyInterface -->
<jx:when
test="${java.lang.Class.forName('com.MyInterface').isAssignableFrom(
object.getClass())}">


Maybe it's a good idea to think some more powerful ways of presenting
(object oriented?) data, so that the statements above could be written
easier? Maybe some form of inheritance when defining macro's, as there
may be some inheritance structure in the data you provide? E.g.

class Vehicle {
  int numberOfWheels;
}

class Car extends Vehicle {
  int fuelType;
}

class Bike extends Vehicle {
  ...
}

(This is obviously a dumb example). Instances of cars and bikes are
formatted differently, except for the numberOfWheels that is defined in
the base class Vehicle (so I want to define the formatting of that
property only once).

This all could be done with the basic JXTemplate building blocks, but it
doesn't make it much more readible in some cases. Also the code is very
verbose, as Leszek says. Maybe it's good to think about some more
powerful methods of formatting data?

Bart.

Mime
View raw message