Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    XMLTools DataSource Overrides

    In want to create my navigation panel dynamically (configured by xml) using SectionStackSections and one TreeGrid per section.
    In my xml file I have defined three sections and within each section one or more nodes defining the content for the TreeGrid within the defined section.
    The TreeGrids I only pass the correct xPath, generate an own DataSource for every grid with its own ID dynamically, that works.

    But before that I want to know how many section entries there are in my xml file to know how many SectionStackSections I have to create.
    Actually I need to read the xml file anyhow, also to find out the name of the subelement of each section (it defines the name of the section).
    I've then read about the XMLTools, but it doesn't work the way I want to.
    Problem is the following call that always returns null (no matter what xPath I specify):
    Code:
    XMLTools.selectString(xmlData, "/navigation");
    Also it's unclear how to find out the number of section nodes with the following method:
    Code:
    XMLTools.selectNodes(xmlData, "/navigation");
    The data object from the transformResponse method only shows: [XMLDoc <navigation>]
    I attached the xml file and the java class, could you please take a quick look at it and give me a hint ...

    Thank you very much.
    Last edited by schmiuwe; 20 Feb 2012, 03:51.

    #2
    I've found a solution using this code in the transformResponse method:

    Code:
    @Override
      protected void transformResponse(DSResponse response, DSRequest request, Object data) {
        JsArray<Element> nodes = ((JavaScriptObject) XMLTools.selectNodes(data, this.getRecordXPath())).cast();
    
        Record[] records = new Record[nodes.length()];
    
        for (int i = 0; i < nodes.length(); i++) {
          Element element = nodes.get(i);
          Node child = element.getChild(0);
          Record record = new Record();
          record.setAttribute(this.getRecordXPath(), child.getNodeName());
          records[i] = record;
        }
    
        response.setData(records);
    
        super.transformResponse(response, request, data);
      }
    In my user interface class I read out the data like this:
    Code:
    SectionDataSource sds = new SectionDataSource("sectionsDS", "//Section", "ds/test_data/navigation.data.xml");
    
        sds.fetchData(null, new DSCallback() {
          @Override
          public void execute(DSResponse response, Object rawData, DSRequest request) {
            Record[] records = response.getData();
    
            for (Record record : records) {
              sections.add((String) record.getAttribute("//Section"));
            }
          }
        });
    Problem is now, it's too late now for my SectionStack to be created according to the loaded data from the DataSource because the records come asynchronous later on so the UI components are already created.
    Is there a possibility to work with the setDataPath method on the SectionStack. The SectionStack does not support setting a DataSource like in e.g. a TreeGrid.
    I attached some files so that you can see what I try to do ...
    Is it anyhow possible to create Sections in a SectionStack dynamically using e.g. an XML DataSource?
    Attached Files
    Last edited by schmiuwe; 20 Feb 2012, 08:35.

    Comment

    Working...
    X