在action层的时候,需要把树的List转换成json的形式,因为extjs树loader只识别json类型的
public void doLoadTree(final ActionMapping mapping, final ActionForm form,
final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
ExplorerForm frm = ( ExplorerForm ) form;
PrintWriter out = response.getWriter();
try {
IFe10001ServiceInterface service = ( IFe10001ServiceInterface ) ComponentFactoryManager
.getInstance().getBeanObject("Fe10001");
List < ExplorerTreeNodeDto > lst = service.loadTree(frm.getFccId(),
frm.getServiceId(), frm.getSubId(), frm.getLinkId(), frm
.getNodeId());
JSONArray ja = new JSONArray();
// 转换成json类型
if (lst != null && lst.size() > 0) {
// 这是jdk1.5以上for的新特性,用for来实现递归
for (ExplorerTreeNodeDto children : lst) {
ja.put(new JSONObject(children));
}
out.write(ja.toString());
}
} catch (SystemException e) {
this.errorOperation(mapping, frm, request, e);
} finally {
out.close();
}
}