AnsweredAssumed Answered

How to foreach an array returned from a Java class in a html webscript?

Question asked by mbel on Nov 9, 2016
Latest reply on Nov 10, 2016 by kaynezhang

Hello,

I have created a webscript and Java class which return some data.

The data is a JSONObject {"data": [{.....}]) which present an array. So, I want somehow to foreach the data in the html.

1st how I can use this JSONObject which comes from Java in a javascript file and after that to foreach it in some <li> element

2nd If I send from the Java class directly an Array, again how to loop it in the html.

I tried using some Freemarker expressions as below:

<#list data>

   <ul>

     <#items as item>

       <li>${item.name}</li>

     </#items>

   </ul>

  <#else>

   <p>Empty</p>

  </#list>

 

But I received the below exception:

freemarker.core.ParseException - Parsing error in template "xxx.post.html.ftl" in line 10, column 22: Encountered ">", but was expecting one of: "as" "." "[" "(" "?" "!" <TERMINATING_EXCLAM> "??" "+" "-" "*" "/" "%" "!=" "=" "==" ">=" <ESCAPED_GTE> ">" <ESCAPED_GT> <LESS_THAN_EQUALS> <LESS_THAN> ".." <AND> <OR>

 

So obviously I haven't understood the syntax...

Could someone assists in both cases when I have an array and when I have JsonObject to use in js file.

Thank you in advance.

Outcomes