3.0 beta 2

jsp + combo box + db load

hi,

could u someone tell me the code in order to fill a combo box in a jsp page, loading the data from a database.

thanks a lot.
jorge auer
January 12,
<html> 
   <head>
      <title></title>
   	<script src="activewidgets2/runtime/lib/aw.js"></script>
   	<link href="activewidgets2/runtime/styles/xp/aw.css" rel="stylesheet"></link>
      <script>
         var request = new AW.HTTP.Request;
         request.setURL("http://www.activewidgets.com/messages/all.rss");
         request.setAsync(false);
         
         request.request();
         var data = request.getResponseXML();
         
         var titleNodes = data.documentElement.getElementsByTagName("title");
         
         var titles = [];
         for( i=0; i<titleNodes.length; i++ )
         {
            titles[i] = titleNodes[i].firstChild.data;
         }
         
      	var obj = new AW.UI.Combo;
    		obj.setItemText(titles);
      	obj.setItemCount(titleNodes.length);
      </script>
   </head>
   <body>
      <script>document.write(obj);</script>
   </body>
</html>


In theory, you should be able to do just this:

var titleNodes = data.documentElement.getElementsByTagName("title");
         
   var obj = new AW.UI.Combo;
   obj.setItemText = function(i) {return titleNodes[i].firstChild.data};
   obj.setItemCount(titleNodes.length);


but i guess this part of the combo control doesn't yet work in Beta3.
dmb
January 12,
<html>
<head>
<title></title>
<script src="activewidgets2/runtime/lib/aw.js"></script>
<link href="activewidgets2/runtime/styles/xp/aw.css" rel="stylesheet"></link>
<script>
var request = new AW.HTTP.Request;
request.setURL("/messages/all.rss");
request.setAsync(false);

request.request();
var data = request.getResponseXML();

var titleNodes = data.documentElement.getElementsByTagName("title");

var titles = [];
for( i=0; i<titleNodes.length; i++ )
{
titles[i] = titleNodes[i].firstChild.data;
}

var obj = new AW.UI.Combo;
obj.setItemText(titles);
obj.setItemCount(titleNodes.length);
</script>
</head>
<body>
<script>document.write(obj);</script>
</body>
</html>
January 13,
thanks a lot, but where are the connections to the db...the select, open, close...etc.??
jorge auer
January 16,
javascript cannot talk directly to a database. This has to be done on the server side. You can use any server side technology (Servlets, JSP, ASP, PHP, etc.) to gerenate XML from a database and return it to your widget.

That's what "/messages/all.rss" in the example above does. It reads forum data from a database and serves it back formatted as XML to whomever asked. Basically, you need to write your own replacement for that URL.

I'd recommend reading up on AJAX, XML and web services. Here's not a bad place to start: http://www.xml.com/pub/a/2005/02/09/xml-http-request.html
Dmitry
January 16,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.