Iterate list in freemaker template

I created a backed java web script for my sample spring surf application. In my class i am setting a list into the model object but when i iterate the list in the template nothing is coming. Its coming blank. My Code is :

@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();
    }

How do i iterate this list? Can any one help or am i doing wrong? I am creating application like this :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

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

My desc file looks like:

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

My ftl file looks like:

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

I want this renderer using java web-scripts. I create the page association for header it is working But when i tried for main page (boxes) the association is happening in header as well as in main page.Can you please help me how can i make page association using java web-scripts ? Is there any sample that you can refer me.

Upvotes: 1

Views: 853

Answers (0)

Related Questions