How to populate json:array from a java array?

393 views
Skip to first unread message

TopGear

unread,
Sep 18, 2007, 11:41:21 AM9/18/07
to json-taglib
Hi All,

I'm getting this output. Property fields are not being filled in.

{"items":[{"ClassId":"${item.classId}","ProgramName":"$
{item.programName}","Description":"${item.description}"}]}

I'm using Weblogic 9.1.

JSP:

<%@ page language="java" contentType="text/x-json; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %>
<%@ page import="com.idt.debit.rate.RatePlans"%>

<jsp:useBean id="ratePlans" class="com.idt.debit.rate.RatePlans"
scope="session">
</jsp:useBean>

<json:object>
<json:array name="items" var="item" items="$
{ratePlans.ratePlans}">
<json:object>
<json:property name="ClassId" value="$
{item.classId}" />
<json:property name="ProgramName" value="$
{item.programName}" />
<json:property name="Description" value="$
{item.description}" />
</json:object>
</json:array>
</json:object>

Java -

package com.idt.debit.rate;

import java.sql.SQLException;
import net.idt.debit.jadmin.dao.core.Classtab;
import net.idt.debit.jadmin.dao.mgr.ClasstabManager;
import com.idt.debit.rate.RatePlan;

public class RatePlans {
public RatePlan[] getRatePlans() throws SQLException {
try {
int i;

Classtab[] ct =
ClasstabManager.getManager().loadAll();

if (ct != null) {
RatePlan _list[] = new
RatePlan[ct.length];

for (i = 0; i < ct.length; i++) {
_list[i] = new RatePlan();


_list[i].setClassId(ct[i].getClassId());

_list[i].setProgramName(ct[i].getProgramName());

_list[i].setDescription(ct[i].getDescription());
}

return _list;
}
} catch(SQLException e) {
throw e;
}

return null;
}
}

Jeremy Sears

unread,
Sep 18, 2007, 12:52:03 PM9/18/07
to json-...@googlegroups.com
Your code looks perfectly fine to me. I'd try the alternate property
syntax to see if that will solve your problem. It may simply be an EL
evaluation issue.

<%@ page language="java" contentType="text/x-json; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %>
<%@ page import="com.idt.debit.rate.RatePlans"%>

<jsp:useBean id="ratePlans" class="com.idt.debit.rate.RatePlans"
scope="session">
</jsp:useBean>

<json:object>
<json:array name="items" var="item" items="${ratePlans.ratePlans}">
<json:object>

<json:property name="ClassId">${item.classId}</property>
<json:property
name="ProgramName">${item.programName}</property>
<json:property
name="Description">${item.description}</property>


</json:object>
</json:array>
</json:object>

I hope that helps.
--
Jeremy Sears

TopGear

unread,
Sep 19, 2007, 7:25:42 PM9/19/07
to json-taglib
Solved by adding <%@ page isELIgnored="false" %> to the jsp and
enabling jsp 2.0 in the web.xml.

Reply all
Reply to author
Forward
0 new messages