2012-04-17 12 views
0

我在将地图渲染到freemarker模板表时出现错误。下面是 是我从控制器获得的实际值的地图。freemarker表格中的渲染地图<String,Object>

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}} 
从我的控制器

现在我想使这个值来我的freemarker模板像

<#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> 

,但我得到的错误

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 

我如何使其在桌子上,请任何人都可以帮助我。

回答

0

List替换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}] 

您可以使用从地图中获取的所有值:当一个地图使用的东西比一个String作为重点别的

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

freemarker的不理解好。 将Map<Object, Object>替换Map<String, Object>可能会解决您的异常。但是您需要使用“name”属性来唯一标识您的对象,并且还需要使用Map的关键字。