English 中文(简体)
Render Map<String,Object> in freemarker table
原标题:Render Map<String,Object> in freemarker table

I am getting error while rendering Map to freemarker template table. below is the map what i am getting from controller with actual values.

Map<Object, Object> hramonths ={4={id=4, empjoindate=16 Nov 2007, description=Apr-2012, editable=T}, 5={id=5, empjoindate=16 Nov 2007, description=May-2012, editable=T}, 6={id=6, empjoindate=16 Nov 2007, description=Jun-2012, editable=T}, 7={id=7, empjoindate=16 Nov 2007, description=Jul-2012, editable=T}, 8={id=8, empjoindate=16 Nov 2007, description=Aug-2012, editable=T}, 9={id=9, empjoindate=16 Nov 2007, description=Sep-2012, editable=T}, 10={id=10, empjoindate=16 Nov 2007, description=Oct-2012, editable=T}, 11={id=11, empjoindate=16 Nov 2007, description=Nov-2012, editable=T}, 12={id=12, empjoindate=16 Nov 2007, description=Dec-2012, editable=T}, 1={id=1, empjoindate=16 Nov 2007, description=Jan-2013, editable=T}, 2={id=2, empjoindate=16 Nov 2007, description=Feb-2013, editable=T}, 3={id=3, empjoindate=16 Nov 2007, description=Mar-2013, editable=T}}

我现在要从我的控制者那里把这一价值变成像我这样的自由标志模板。

<#list hramonths as indication>
                <tr>
                    <td class="center">
                        <#list monthlyrent as rent>
                            <#if indication.id == rent.month><input type="hidden" name="locationIndicatorId_${indication.id}" value="${indication.id}" /> </#if>
                        </#list>    
                    </td>
                    <td class="center">
                        ${indication.description}  <input type="hidden" name="month_${indication.id}" id="month_${indication.id}" value="${indication.id}" />
                    </td>
                    <td class="center">
                        <# assign varIndicatorId ="">
                        <#list monthlyrent as rent>
                            <#if indication.id == rent.month>
                                <# assign varIndicatorId = ${rent.Indicator}>
                            </#if>
                        </#list>                    
                        <select name="indicator_${indication.id}" <#if indication.editable == "F"> disabled="true" </#if> <#if editable == false>disabled="true"</#if>>
                            <#list indicators as indicator>
                                <option value="${indicator.cid}" <#if indicator.cid == varIndicatorId> selected </#if>>
                                    ${indicator.description}
                                </option>
                            </#list>
                        </select>
                    </td>
                    <td class="right">
                        <#if mothlyrentsize != "0"> 
                            <#list monthlyrent as rent>
                                <#if indication.id == rent.month>
                                    <input type="text" align="right" name="rent_${indication.id}_${rent.cid}" 
                                        value="$DelphiNumber.formatNumber("$!rent.rent")"  
                                        <#if indication.editable == "F"> 
                                        readonly="true" class="rbox" </#if> 
                                        <#if editable == false>
                                            readonly="true" class="rbox"
                                        </#if>
                                        <#if indication.editable != "F" && editable != false>
                                            onBlur="isnumeric(this.form,this),updateHRATotalAll(this.form, blurtype )"
                                    </#if> />                           
                                </#if>
                            </#list>                    
                        <#else>
                            <input type="text" name="rent_${indication.id}_0" value="$DelphiNumber.formatNumber("0")" 
                                #if("$!indication.editable" == "F") 
                                readonly="true" class="rbox" #end 
                                #if($editable == false)
                                    readonly="true" class="rbox"
                                #end
                                style="TEXT-ALIGN: right"
                                #if("$!indication.editable" != "F" && $editable != false)
                                    onBlur="isnumeric(this.form,this),updateHRATotalAll(this.form, blurtype )"  
                                #end >
                            </input>    
                        </#if>  
            </td>                               
        </tr>
    </#list>

but i am getting error

Expected collection or sequence. hramonths evaluated instead to freemarker.template.SimpleHash on line 199, column 40 in WEB-INF/classes/com/greytip/cougar/module/epayroll/v2/freemarker/salary/it-declaration.ftl. The problematic instruction: ---------- ==> list hramonths as indication [on line 199, column 33 in WEB-INF/classes/com/greytip/cougar/module/epayroll/v2/freemarker/salary/it-declaration.ftl] ----------  Java backtrace for programmers: ---------- freemarker.template.TemplateException: Expected collection or sequence. hramonths evaluated instead to freemarker.template.SimpleHash on line 199, column 40

如何在表格上填写,请任何人帮助我。

问题回答

替换为<代码>Map。 因此,它希望:

List<Object> hramonths =[
    {id=4, empjoindate=16 Nov 2007, description=Apr-2012, editable=T}, 
    {id=5, empjoindate=16 Nov 2007, description=May-2012, editable=T}, 
    {id=6, empjoindate=16 Nov 2007, description=Jun-2012, editable=T}]

你们能够利用所有价值观:

Collection<Object> hramonthsValues = hramonths.values();

freemarker doesn t understand well when a Map uses something else than a String as a key. Replacing your Map<Object, Object> by a Map<String, Object> may resolve your exception. But you will need to use a "name" attribute to uniquely identify your Object, and also as a key for the Map.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签