Re: Listing enumerations
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Friday, March 9, 2012, 11:17:27 PM, Tim Pizey wrote:
> On 9 March 2012 21:26, Daniel Dekany wrote:
>> What's the Java class and method behind database.displayTables?
>
> It was:
>
> public Enumeration<Table> displayTables() {
> return displayTables(PoemThread.inSession() ?
> PoemThread.transaction() : null);
> }
>
>
> I have changed the template to
> <#list melati.database.getDisplayTables() as table>
>
> which uses
>
> public List<Table> getDisplayTables() {
> return EnumUtils.list(displayTables());
> }
>
> which has moved me on to the next problem!
>
> (Melati, being ancient) does use a lot of Enumerations)
But
public Enumeration<Table> displayTables()
is fine for FreeMarker, you just have to call it as:
<#list melati.database.displayTables() as table>
Note the "()". Since displayTables is just a method, not a JavaBean
property, you have to call it to get the result. Otherwise you just
get the method itself. (Or, of course, you can use BeansWrapper
fine-tuning to expose these methods as if they were properties.)
> thanks for all your help
> Tim
>
>
>
>> --
>> Best regards,
>> Daniel Dekany
>>
>>
>> Friday, March 9, 2012, 6:31:24 PM, Tim Pizey wrote:
>>
>>> Hi,
>>>
>>> I have a method which returns an Enumeration, but when it is rendered
>>> with #list or #foreach
>>> an exception is thrown:
>>>
>>> ?size is unsupported for: freemarker.ext.beans.OverloadedMethodModel
>>> The problematic instruction:
>>> ----------
>> ==>> list melati.database.displayTables as table [on line 67, column 50
>>> in org/melati/admin/Top.fml]
>>> ----------
>>>
>>> Java backtrace for programmers:
>>> ----------
>>> freemarker.template.TemplateModelException: ?size is unsupported for:
>>> freemarker.ext.beans.OverloadedMethodModel
>>> at
>>> freemarker.ext.beans.OverloadedMethodModel.size(OverloadedMethodModel.java:149)
>>> at
>>> freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:174)
>>> at freemarker.core.Environment.visit(Environment.java:428)
>>>
>>> The template is:
>>>
>>> <select name="table" OnChange="submit();" title="Select table to edit">
>>> <#assign lasttype = "">
>>> <#assign selected = false>
>>> <#list melati.database.displayTables as table>
>>> <#if !table.tableInfo.category.equals(lasttype)>
>>> <option value=""> </option>
>>> <option value="">${table.tableInfo.category.name}</option>
>>> <option value="">============</option>
>>> </#if>
>>> <#assign lasttype = table.tableInfo.category>
>>> <option value="${table.name}"
>>> <#if !selected>
>>> <#if melati.table>
>>> <#if melati.table.equals(table)>
>>> selected="selected"
>>> <#assign selected = true>
>>> </#if>
>>> <#else>
>>> <#if table.getName().equals(admin.getPrimaryDisplayTable(melati))>
>>> selected="selected"
>>> <#assign selected = true>
>>> </#if>
>>> </#if>
>>> </#if>> ${ml.rendered(table.displayName)}</option>
>>> </#list></select>
>>>
>>>
>>> I am using BeanWrapper.
>>>
>>> The documentation for #list
>>> http://freemarker.sourceforge.net/docs/ref_directive_list.html
>>> says, as far as I can understand, that an enumeration and and iterator
>>> should be usable.
>>>
>>> Sorry if this is a newbie error.
>>>
>>> thanks in advance
>>> Tim
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user