This patch allows template classes that implement more than one TemplateModel to work as expected.
In particular, classes that implement both TemplateHashModel and TemplateListModel now enjoy a more predictable behaviour. The behaviour is as follows:
When using dynamic key names, for instance:
template[ 4 ]
template[ "4" ]
template[ keyname ]
template[ "keyname" ]
FreeMarker will first check whether the class implements a TemplateListModel. If so, it will then attempt to parse the key as an Integer. If it succeeds, the integer will be used as an index into the TemplateListModel.
If the key name cannot be resolved as an integer, FreeMarker next checks if the key name is the string "size". If so, it will get the TemplateModel from the listSize() method of the TemplateListModel.
If the key name is still unresolved, and the class also implements TemplateHashModel, FreeMarker will use the key name as a lookup into the TemplateHashModel.
Similarly, when using dot notation, such as:
FreeMarker first determines whether the class implements a TemplateHashModel. If so, it will lookup the key name using the TemplateHashModel.
If the result was null, _and_ the key name was "size", _and_ the class also implements TemplateListModel, FreeMarker will then call the listSize() method of the TemplateListModel.
Otherwise, if the class does not implement TemplateHashModel, and does implement TemplateListModel, and the key name was "size", FreeMarker returns the listSize() method.
All of this is a very long-winded way of saying the FreeMarker now does what you expect in these cases. Both dynamic key names and dot notation will work -- dynamic key names favour the ListModel, while dot notation favours HashModel.
Nicholas Cull ( run2000 ) - 2001-04-17 07:16:12 PDT
|MultiModel.zip||Allows classes implementing multiple models to work as expected||Download|