Tracker: Patches

5 Enhance: Support for multiple models - ID: 416701
Last Update: Comment added ( run2000 )

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:

template.keyname

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

5

Closed

Fixed

Nicholas Cull

None

None

Public


Comment ( 1 )

Date: 2001-05-05 20:57:06 PDT
Sender: run2000

Logged In: YES
user_id=137221

Checked in in a modified form: removed the coding for "size" key,
since listSize() is probably going to disappear soon.


Attached File ( 1 )

Filename Description Download
MultiModel.zip Allows classes implementing multiple models to work as expected Download

Changes ( 5 )

Field Old Value Date By
status_id Open 2001-05-05 20:57:06 PDT run2000
resolution_id None 2001-05-05 20:57:06 PDT run2000
assigned_to nobody 2001-05-05 20:57:06 PDT run2000
close_date - 2001-05-05 20:57:06 PDT run2000
File Added 5465: MultiModel.zip 2001-04-17 07:22:24 PDT run2000