:: Forum >>

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
Thursday, January 12, 2006
<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
Thursday, January 12, 2006
<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>
Friday, January 13, 2006
thanks a lot, but where are the connections to the db...the select, open, close...etc.??
jorge auer
Monday, January 16, 2006
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 "http://www.activewidgets.com/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
Monday, January 16, 2006

This topic is archived.


Back to support forum

Forum search