Two Java classes are defined as follows:
public class Abc{
private List<SomeOtherClass> someClass;
private String k;
private String m;
}
public class SomeOtherClass{
private String a;
private String b;
private String c;
}
On a JSP page, a bean of class Abc is being created as shown below:
<jsp:useBean id="someId" class="Abc" scope="request" />
Within this JSP page and inside a script tag, a JavaScript array of JSON objects is being attempted to be created:
<script>
var abc = (function(){
module._myFunction = {
"key1" :"<c:out value = '${someId.k}'/>",
"key2" :{
<c:forEach varStatus='status' items='${someId.someClass}' var ="xyz">
"subKey1":"${xyz.a}",
"subKey2":${xyz.b}
</c:forEach>
}
}
}(abc || {}))
</script>
However, there is an error of "Unexpected string" due to the code inside the c:forEach loop. Omitting subKey1 & subKey2 makes it work fine, which is expected. Is there a way to create this JSON array successfully and check abc.key2.subkey1
or abc.key2.subKey2
in the developer console?
abc.key2.subkey1 or abc.key2.subKey2 in developer console