使用基于XML的DataSource的Drag Drop在SmartGWT中不起作用

时间:2012-02-27 14:36:29

标签: java gwt smartgwt

我正在使用这个例子:

http://www.smartclient.com/smartgwt/showcase/#tree_interaction_drag_nodes

但是将数据源更改为XML文件,现在它无法正常工作。

使用的XML是:

<RootNode>
<ChildNode>
    <ChildID>2</ChildID>
    <Name>ChildNode1</Name>
    <ReportsTo>1</ReportsTo>
</ChildNode>
<ChildNode>
    <ChildID>3</ChildID>
    <Name>ChildNode1.1</Name>
    <ReportsTo>2</ReportsTo>
</ChildNode>
<ChildNode>
    <ChildID>4</ChildID>
    <Name>ChildNode2</Name>
    <ReportsTo>1</ReportsTo>
</ChildNode>
<ChildNode>
    <ChildID>5</ChildID>
    <Name>ChildNode2.1</Name>
    <ReportsTo>4</ReportsTo>
</ChildNode>
<ChildNode>
    <ChildID>6</ChildID>
    <Name>ChildNode2.1.1</Name>
    <ReportsTo>5</ReportsTo>
</ChildNode>
</RootNode>

而对于grid1和grid2,我将数据源更改为xml文件,如下所示:
而不是:

grid1.setData(grid1Tree);  
grid1.getData().openAll(); 

我正在使用:

    grid1.setAutoFetchData(true);  
    grid1.setDataSource(EmployeeXmlDS.getInstance());    
    grid1.draw();

同样对于grid2。 这是EmployeeXmlDS实现:

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;


public class EmployeeXmlDS extends DataSource {

    private static EmployeeXmlDS instance = null;

    public static EmployeeXmlDS getInstance() {
        if (instance == null) {
            instance = new EmployeeXmlDS("employeesDS");
        }
        return instance;
    }

    public EmployeeXmlDS(String id) {

        setID(id);
        setTitleField("Name");
        setRecordXPath("/RootNode/ChildNode");
        DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128);
        DataSourceIntegerField childIdField = new DataSourceIntegerField("ChildID", "Child ID");
        childIdField.setPrimaryKey(true);
        childIdField.setRequired(true);
        DataSourceIntegerField reportsToField = new DataSourceIntegerField("ReportsTo", "Parent");
        reportsToField.setRequired(true);
        reportsToField.setForeignKey(id + ".ChildID");
        reportsToField.setRootValue("1");
        setFields(nameField,childIdField,reportsToField);
        setDataURL("ds/test_data/tree2.xml");
        setClientOnly(true);
    }
}

请帮忙。

0 个答案:

没有答案