在freemarker模板中迭代列表

时间:2013-10-28 16:25:16

标签: java spring-mvc freemarker alfresco-share spring-surf

我为我的示例spring surf应用程序创建了一个支持的java Web脚本。在我的班级中,我正在设置模型对象的列表,但是当我在模板中迭代列表时,什么都没有。它的空白。 我的代码是:

@Controller
public class Example extends AbstractWebScript{

    @Override
    public void execute(WebScriptRequest req, WebScriptResponse res)throws IOException {

        System.out.println("java backed webscripts called");

        System.out.println("BOOM");

        Map<String, Object> model = new HashMap<String, Object>();
        HttpServletRequest httpRequest = ServletUtil.getRequest();

        if(AuthenticationUtil.isAuthenticated(httpRequest)){
            model.put("userId", AuthenticationUtil.getUserId(httpRequest));
        }else{
            model.put("userId", "guest");

        }

        Writer writer = res.getWriter();

        String templatePath = "webscripts/example.get.html.ftl";



        //Java
        List<String> cityList = new ArrayList<String>();

        cityList.add("Washington DC");
        cityList.add("Delhi");
        cityList.add("Berlin");
        cityList.add("Paris");
        cityList.add("Rome");

        model.put("username", "ranveer");
        model.put("cityList", cityList);

        ((WebScriptServletRequest) req).getHttpServletRequest().getSession().setAttribute("lastName", "singh");     
        renderTemplate(templatePath, createTemplateParameters(req, res, model), writer);

        writer.flush();
        writer.close();
    }

我如何迭代此列表?任何人都可以帮忙或我做错了吗?我正在创建这样的应用程序:These link 1, link 2 and link 3 are header part which will go to next pages.All the boxes are the components which all will go to the same page.I made these all boxes as components so that i can include them

这些链接1,链接2和链接3是标题部分,它将转到下一页。所有框都是所有将转到同一页面的组件。我将这些所有框作为组件,以便我可以包含它们

我的desc文件看起来像:

<webscript>
<shortname>Industry</shortname>
<description>Returns the main page content for the index page.</description>
<url>/home/box1</url>
</webscript>

我的ftl文件如下:

<#if renderer == "horizontal">
<@horizontal page=rootpage showChildren=true/>
</#if>
<#macro horizontal page showChildren>
<#-- Children of Home Page -->
<#list sitedata.findChildPages(page.id) as parentPage>
<li>
<#assign href = linkbuilder.page(parentPage.id, context.formatId)>
<#assign classId = ''>
<#if parentPage.id == context.page.id>
<#assign classId = 'current'>
</#if>
<a href='${href}' id='${classId}'>${parentPage.title}
</a>
</li>
</#list>
</#macro>

我希望这个渲染器使用java web-scripts。 我创建了它正在工作的页面的页面关联但是当我尝试主页(框)时,关联发生在标题和主页面中。你能帮助我如何使用java web-scripts进行页面关联?有没有你可以推荐我的样品。

0 个答案:

没有答案
相关问题