Announcement

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

    In SmartGWT Client, How to load an XML document as a data structure?

    1. Currently using Smart GWT v2.5 against Weblogic 10.3.5 in Firefox 5.0
    (SmartClient Version: SC_SNAPSHOT-2011-07-27/LGPL Development Only (built 2011-07-27))

    I have the beginnings of a new SmartGWT frontend for my preexisting Weblogic/JSP/servlet application, using several ListGrids to load data from a RESTful datasource. All of that works smoothly, now.

    However, I now want to grab the "current session information", such as "current project selected", and "current user information", and display that as part of a set of status fields in the Toolstrip I've got across the top of the screen.

    As this doesn't look like a preexisting control, what I'm looking for is a way to grab an XML document from the server and parse it within SmartGWT client to provide me with a datastructure that contains the information I want. I can then put the data out into labels/canvases, etc as per my requirements.

    What is the recommended way to load data into a SmartGWT Client application, where that data is not loaded into a predefined widget via DataSource?

    Alternatively, assuming I was going to create an invisible ListGrid to do this, what steps do I need to take such that the ListGrid will fetch the data from a RESTful datasource without having to display it on screen?
    (My experiments in doing this have thus far been unsuccessful)

    Thanks,
    jsres

    #2
    Bah.
    Nevermind. This is a pure GWT issue, which is why all my google queries with "+smartgwt" never found it.

    http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsXML.html

    Code:
    private void parseMessage(String messageXml) {
      try {
        // parse the XML document into a DOM
        Document messageDom = XMLParser.parse(messageXml);
    
        // find the sender's display name in an attribute of the <from> tag
        Node fromNode = messageDom.getElementsByTagName("from").item(0);
        String from = ((Element)fromNode).getAttribute("displayName");
        fromLabel.setText(from);
    
        // get the subject using Node's getNodeValue() function
        String subject = messageDom.getElementsByTagName("subject").item(0).getFirstChild().getNodeValue();
        subjectLabel.setText(subject);
    
        // get the message body by explicitly casting to a Text node
        Text bodyNode = (Text)messageDom.getElementsByTagName("body").item(0).getFirstChild();
        String body = bodyNode.getData();
        bodyLabel.setText(body);
    
      } catch (DOMException e) {
        Window.alert("Could not parse XML document.");
      }
    }
    Apologies.

    Comment

    Working...
    X