Announcement

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

    XML Datasource settings for a cascaded XML structure

    Hi Folks,

    after some years, I'm back giving the SmartGWT/Eclipse stuff another try.
    Unfortunately I start stumbling after the 3rd day which in turn is the proof that I only got older during the last years, and not wiser :-(

    However, you guys will tell me.

    I try to load a TreeGrid with an XML file of cascaded content.

    The XML look like:

    Code:
    <Products>
       <Product>....</Product>
       <Product>...
          <Product>...
             <Product>....</Product>
             <Product>....</Product>
          </Product>
       </Product>
    </Products>
    I already noticed from the docs and from the web, that you normally have (or need) a primary (unique) and a common key. But I don't have them. I only have a primary ID attribute within <Product> (but no common child keys).
    In the web I found an idea, solving it via setValueXpath but I receive an "uncaught exception". BTW: I'm using SmartGWT 3.0p LPGL.

    Here's my DataSource (I dropped the instantiation):
    Code:
    setID(id);  
    setTitleField("Name");  
    setRecordXPath("/Products/*");
            
    DataSourceTextField productField = new DataSourceTextField("Product", "Product", 128);
    productField.setRequired(true);
    productField.setChildrenProperty(true);
    // productField.setMultiple(false);
            
    DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128);  
    nameField.setValueXPath("Product/Name");
    
    setFields(productField, nameField);  
    setDataURL("ds/test.xml");  
    setClientOnly(true);
    I'm wondering a little bit, that I haven't found any similar sample or request because such kind of cascaded XML structure looks very common for me.

    Does anyone has an idea ?

    #2
    Okay, two days later and after reading tons of docs as well as 6475 forum snippeds, I'm pretty sure that I do not need to do some complicated stuff like transformResponse or xmlSerialize. Instead of it looks like it should work out of the box.

    Like:

    Code:
    ...
    setID(id);  
    setRecordXPath("/Products/Product/Product[@UserTypeID='Product Folder']");
    
    DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128); <-- I didn't listed that in my XML sample
    nameField.setValueXPath("./Name");
    
    DataSourceTextField idField = new DataSourceTextField("ID", "ID", 128);
    idField.setValueXPath("./@ID"); <-- I didn't listed that in my XML sample
    
    DataSourceField childs = new DataSourceTextField("Product", "Product");
    
    childs.setValueXPath(".//Product");
    childs.setMultiple(true); <-- true|false doesn't matter
    childs.setChildrenProperty(true);
    ...
    I can see my root entries, but when opening one of them, I still receive an "Uncaught exception".
    Without the setChildrenProperty(true), I can open the nodes, but always get my root nodes listed as childs again.

    I'm really at the end of ideas and tried everything (which is in the scope of my knowledge) :-(

    Anybody out there who can point me into the right direction ?

    Comment

    Working...
    X