1

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.

Frederic Close
  • 9,389
  • 6
  • 56
  • 67
  • A lot of information missing here: where are you trying to deploy the webscript? How does the descriptor look like? And how does your template look like? Anything in the logs, proving that your webscript is actually executed? And why dont you use DeclarativeWebscript? – Gyro Gearless Oct 28 '13 at 16:46
  • What does your FTL look like? Are you outputting any static text that you expect to show up? Maybe the issues are in what Gyro was saying -- you might not be executing your script at all. – Charles Forsythe Oct 28 '13 at 17:10
  • I want to create a Webscript which will get all the child pages.This is the sample webscript i wrote.Can you help me how can i build a webscript which will get all the child pages for page association. – Ranveer Singh Rajpurohit Oct 28 '13 at 18:16
  • As far as I can tell, your FTL looks fine. One suggestion for debugging: add some text that will always output from your FTL; this helps you know whether it's even being run. Right now, you get the same result if the script doesn't run or if `siteData.findChildPages` returns an empty list for some reason. Sorry I can't advise you on WebScripts. – Charles Forsythe Oct 29 '13 at 12:28

0 Answers0