Search code examples
jspdwr

How can i handle with DWR.. if my java class return xml data


StockDetails.java

public class StockDetails {

    public String getDetailsBySymbol(String symbol){
        StockQuote stockQuote = new StockQuote();
        StockQuoteSoap stockQuoteSoap = stockQuote.getStockQuoteSoap();
        return stockQuoteSoap.getQuote(symbol);
    }

}

and it returns stockquote in xml format

in client side jsp file index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Dwr Example</title>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
<script type='text/javascript' src='dwr/interface/StockDetails.js'>
</script>
 <script>
       function getMessageFromServer()
       {
           var symbol = DWRUtil.getValue("companySymbol");
            DWRUtil.setValue("response", "");
            StockDetails.getDetailsBySymbol(gotResult, symbol);
       }
       function gotResult(symbol)
       {
           DWRUtil.setValue("response", symbol);
       }
  </script>
 </head>
    <body>
        <p>
            <input type="text" id="companySymbol"></input><br> 
            <button onclick="getMessageFromServer()">Click</button><br><br>
        </p>
        <p>
            <span id="response">Response appear here..</span>
        </p>

    </body>
</html>

it displays like a normal text how can i display in for structural format like

Company name :
Start price :
closed price :

any idea?


Solution

  • You can use downloadxml.js to parse data, built a html table and after fill fields with jquery `var xml = xmlParse(data);

    for (var i=0; i < data.length; i++ ){

                $("#fila"+i).find("#field1").text(data[i].field1);
                $("#fila"+i).find("#field2").text(data[i].field2);
                ...........
    

    }

    `