Submitted by Syd Nicholson on Wed, 11/29/2006 - 00:00
Forums

Does anybody have any examples of the use of XML/XSL with AJAX in IceBreak?

There is a good tutorial in the iceBreak administration server on the use of XML/XSL but this tutorial does not use ajax.

I am especially interested in how the XML response sent by the server can be formated in a section of the browser window.

Can IceBreak's adAjaxCall() be used for this purpose, or are there other functions in the Ajax.js script that would be more siutable?

Thanks in advance
Syd

Niels Liisberg

Wed, 11/29/2006 - 00:00

Hi Syd;

This sample uses a XML data island within the application. You can simply add the adAjaxCall to create the XML externally :

 
  <%
 H*' --------------------------------------------------------------------------------
  H*' List of product using XML data island provided by SQL
 H*' supported by Internet Explorer
  H*' --------------------------------------------------------------------------------
  D*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++Comments++++++++++++
 D Error           s               N
 D SqlCmd          s           1024    varying
 D MaxRows         s             10i 0
 /free
   *inlr   = *on;
 %>
 <html>
  <head>
   <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
   <link rel="stylesheet" type="text/css" href="/System/Styles/IceBreak.css"/>
  <title>Product master</title>
 </head>
 <body>
   <h1>Product master</h1>
  <br />
   <input type=button onclick="tableData.firstPage()" value="|<" id=button1 name=button1>
  <input type=button onclick="tableData.previousPage()" value="<<" id=button2 name=button2>
  <input type=button onclick="tableData.nextPage()" value=">>" id=button3 name=button3>
  <input type=button onclick="tableData.lastPage()" value=">|" id=button4 name=button4>
   <br />
   <br />
   <br />
   <table datasrc="#xmlData" id="tableData" datapagesize="20" width="100%" border="1">
   <thead>
     <tr>
      <th>Product Key</th>
      <th>Product ID</th>
       <th>Description</th>
      <th>Manufacturer ID</th>
      <th>Price</th>
      <th>Stock Count</th>
      <th>Stock Date</th>
     </tr>
    </thead>
   <td><span datafld="PRODKEY"></span></td>
   <td><span datafld="PRODID"></span></td>
    <td><span datafld="DESC"></span></td>
    <td><span datafld="MANUID"></span></td>
    <td><span datafld="PRICE"></span></td>
   <td><span datafld="STOCKCNT"></span></td>
    <td><span datafld="STOCKDATE"></span></td>
  </table>
   <xml id="xmlData">
  <%
    SqlCmd  = 'Select '
            + '  PRODKEY   ,'
            + '  PRODID    ,'
             + '  DESC      ,'
             + '  MANUID    ,'
             + '  PRICE     ,'
            + '  STOCKCNT  ,'
             + '  STOCKDATE '
             + 'From product';
     MaxRows = 10000;
    Error   = SQL_Execute_XML(sqlcmd : maxrows);
 %></xml>
 <%
    if (Error);%>
      <p class="errmsg"><%= getLastError('*MSGTXT')%></p>
       <p class="errmsg2"><% = getLastError('*HELP')%></p>
  <%
    endif; %>
 </body>
 </html>

Thanks Niels,

I think I see how to do this. I would like to clarify a few points to help me understand what is happening here.

1. I assume that the adAjaxCall() procedure calls are in the onclick() procedures of the buttons.

2. The adAjaxCall returns XML for the id="xmlData" section of the page.

Is it possible, using this technique, to 'grey out' or 'hide' buttons that are not appropriate (eg. disable the 'previous page' button when the first record is on the display, or the 'next page' button when the last page is on the display?

Thanks once again
Syd

Further to my previous reply - I have further questions

Currently I am using Ajax to send HTML to a page after certain options have been selected on that page (eg. Page Up, Page down, Search for value, etc). The "subfile" being displayed has an HTML "Select" box in the left hand column with several options available for each of the records in the table.

In order to biuld this table and set the appropriate status for the buttons on the page the Ajax process returns almost all of the HTML for the page, including the HTML for the buttons (with the correct status), the table column titles, etc. In fact most of the page is being refeshed.

I would like to move to the concept of the data island where only the table contents are replaced by Ajax using XML. So - my questions are:

1. Have I already used the most efficient method of handling this browser page?
2. If the answer to 1. above is no, can the method outlined previously in this question be used to achieve my goal, and if so how?
3. If the answer to 2. is no, then can the functions present in Ajax.js be used to return the XML to a JavaScript procedure (perhaps a user defined call back procedure) which would then use the XML to construct the table (including the 'select' pull down controls in the left hand column) and set the button status values?

Many thanks in advance
Syd

Hi Syd ... lots of questions there !!

But regarding  returnig ajax as an object you realy !! MUST !! look at JSON. which is simply sending Java Script Object Notation over the http, so you have a full blown object after the ajax call .... super cool stuff 


Icebreak already support a JSON component for SQL querys like: 

<script>

   var obj = <% Error = SQL_Execute_JSON(sqlcmd : maxrows); %>

</script>

(SQL_Execute_JS for older versions of IceBreak ) 

Where sqlcmd is a RPG variable with a SQL select statement

JSON rocks !! 

Niels

Thanks Niels,

This looks very interesting. Must investigate further.

I was actually looking for something that did not use SQL.

When dealing with pages of data from a large file (several tens of thousands of records), handling page up, and page down with SQL is quite difficult. An SQL cursor can handle this in RPG, but standard SQL statements are ideally suited to this way of working. Showing the next page (page down) or positioning to a specific record isn't too difficult, but it is difficult to page up - how does one know if there is a previous page, and on what record does this page start?

I have now succeeded in handling this situation with a bit of help from an Ajax book. I have created my own Ajax javascript that allows me to specify my own call back routines - These routines handle the data (XML) and put it the web page, and also set properties for elements such as disabling the appropriate buttons if there is no previous or next page.

However, JSON looks like an excellent way to handle smaller files, or subsets of data, and I must play with this and see what happens.

Thanks once again
Syd
 

Hi Syd;

It sounds interesting and cool - You have to show me your stuff

JSON : Just think about JSON as a concept: moving objects over the http protocol as fast as possible.

However ther is not a parser (yet) for JSON in IceBreak. So today you will request data with an normal URL - and then return the ojbect as JSON to the javascript

So:
1) JSON from icebreak to the client. 
2) URL qrystr / FORM / XML from the client to IceBreak. 


Niels

Could you expand a little more on this JSON stuff - Just to help my understanding of what is happening.

1. The obj returned from the SQL call, how is this used. Is it an array to be used like obj[i].fieldname?

2. Is SQL the only JavaScript object that can be used, or are there others?

Regards
Syd

Hi Syd,

First of all... if you are working with cross-browser, cross-OS and standards then you have absolutely NO use of "XML data island"! It simply WON'T work! You should be looking for alternatives like Ajax so that your customers can switch OS and/or browser without having to change your programs.

As Niels have written you can use JSON to return data. It is efficient because what you do is actually return the JavaScript code that could be executed to build the (X)HTML syntax. But be aware that if you create WebServices that returns JSON then you also need to create a WebService to return the data as XML if other business logics need the same data. XML is far better if you need to deploy solutions that should be callable from other applications on other platforms.

I do not have the time right now to construct or find the code to get XML using Ajax and transform (XSLT) it using XSL into result as HTML or whatever. Maybe we can take this another day if you need it.

Best regards,

John Foldager
www.izone.dk