日期:2014-05-18  浏览次数:21037 次

在freemaker里写了个嵌套list一直报错,网上查了好多都不管用,请各位大神给看看,很着急在线等!!!!
在freemaker里写了个嵌套list一直报错,网上查了好多都不管用,请各位大神给看看,很着急在线等!!!!

freemaker代码:
<#list devicesList as device>
     ${device.ipAddress}
     ${device.hardwareVendor}
      <#list device.ipAddress as pojo2>
             ${pojo2.policyTag}
           ${pojo2.policyName}
      </#list>
</#list>

把device.ipAddress 改成固定的字符串以后不再报错,但在网上看到别人也是这样写的就没事,而且将   <#list device.ipAddress as pojo2>改为<#assign policys = device.ipAddress><#list policys as pojo2>一样报错!!

java 代码:

List<NDeviceLite> deviceLites = new ArrayList<NDeviceLite>();
for (int j = 0; j < 2; j++)
{
NDeviceLite device = new NDeviceLite();
device.setIpAddress("10.1.9.1" + j);
device.setHardwareVendor("cisco");
deviceLites.add(device);

List<ComplianceStatisticsPojo> _pojos = new ArrayList<ComplianceStatisticsPojo>();
for (int i = 1; i < 5; i++)
{
ComplianceStatisticsPojo _pojo = new ComplianceStatisticsPojo();
_pojo.setPolicyName("7.1.2.02.b(Cisco_G)");
_pojo.setPolicyTag("网络访问控制");
_pojos.add(_pojo);
}
dataMap.put("poj", _pojos);
}
dataMap.put("devicesList", deviceLites);



报错信息:
Expected collection or sequence. device.ipAddress evaluated instead to freemarker.template.SimpleScalar on line 1170, column 8 in GradeProtection.ftl.
The problematic instruction:
----------
==> list device.ipAddress as pojo2 [on line 1170, column 1 in GradeProtection.ftl]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateException: Expected collection or sequence. device.ipAddress evaluated instead to freemarker.template.SimpleScalar on line 1170, column 8 in GradeProtection.ftl.
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:135)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:190)
at freemarker.core.Environment.visit(Environment.java:415)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
at freemarker.core.Environment.visit(Environment.java:208)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:208)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
at freemarker.core.Environment.visit(Environment.java:415)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
at freemarker.core.Environment.visit(Environment.java:208)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:208)
at freemarker.core.Environment.process(Environment.java:188)
at freemarker.template.Template.process(Template.java:237)
at org.netcengfig.compliance.DocumentHandler.createDoc(DocumentH