xloadtree终于弄出些眉目,不过又有了新问题
xloadtree要求加载的xml文件格式是一定的,比较麻烦,今天弄了一下午,终于有些眉目,不过又有了新问题,文件如下
1。jsp显示
<script type= "text/javascript ">
var tree = new WebFXLoadTree( "列表 ", "showTree.do?GetType=0 ",null, "doNothing() ")
function doCategoryAction(name){
alert(name)
}
function doPriCategoryAction(name){
alert(name)
}
function doNothing()
{
}
tree.write(); //应该生成树了,但是没有显示
</script>
2。struts的action
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String strXML = " <?xml version=\ "1.0\ " encoding=\ "gb2312\ "?> \n ";
strXML += "\t <tree> \n ";
int getType = Integer.parseInt((String)request.getParameter( "GetType "));
if (getType == 0){
//获取所有主分类的XML
strXML += MakePriCategorySetXML();
}
strXML += "\t </tree> \n ";
System.out.println(strXML);
return(mapping.findForward( "showtree "));
}
/**
* 创建每一个节点的XML文本
*/
private String MakeItemXML(String username, String action, String src,
String icon, String openIcon) {
String strXML = "\t ";
strXML += " <tree text=\ " "+username+ "\ " ";
strXML += " action=\ " "+action+ "\ " ";
if (src != null) {
strXML += " src=\ " "+src+ "\ " ";
}
if (icon != null) {
strXML += " icon=\ " "+icon+ "\ " ";
}
if (openIcon != null) {
strXML += " openIcon=\ " "+openIcon+ "\ " ";
}
strXML += "/> \n ";
return strXML;
}
/**
* 获取所有主分类节点的XML文本
* @return String
*/
private String MakePriCategorySetXML() {
String strXML = " ";
try {
String username= " ";
int userid;
Session session=HibernateSessionFactory.getSession();
String hql= "from Regs as a ";
List list = session.createQuery(hql).list();
Iterator it = list.iterator();
while(it.hasNext())
{
Regs reg = (Regs)it.next();
username = reg.getUsername();
userid=reg.getId();
String action = "javascript:doPriCategoryAction( ' " + username + " ') ";
String icon = "/images/folder.png ";
String openIcon = "/images/openfolder.png ";
String src= "/visitFriend.do?fid= "+userid;
strXML += MakeItemXML(username, action, src, icon, openIcon);
}
}
catch (Exception ex) {}
return strXML;
}
[解决办法]
java控制台显示生成的xml文件
<?xml version= "1.0 " encoding= "gb2312 "?>
<tree>
<tree text= "roroya " action= "javascript:doPriCategoryAction( 'roroya ') " src= "/visitFriend.do?fid=8 " icon= "/images/folder.png " openIcon= "/images/openfolder.png "/>
<tree text= "abc " action= "javascript:doPriCategoryAction( 'abc ') " src= "/visitFriend.do?fid=9 " icon= "/images/folder.png " openIcon= "/images/openfolder.png "/>
</tree>
为什么text里面会有那么多空格?
问题,既然xml已经生成了,为什么不显示树?请高手指教!!!谢谢!!!