Skip to main content

dojo + xml

1 reply [Last post]
kevcpu
Offline
Joined: 2007-01-07
Points: 0

I have been trying to implement dojo but I am receiving errors when I retrieve the response. I dont see where the problem lies. Does anyone have any examples of retrieving xml from a jsf page. The type parameter seems to have a value of 'error'. Here is my code:

index.jsp:

Dojo: Hello World!

dojo.require("dojo.event.*");

// Load Dojo's code relating to widget managing functions
dojo.require("dojo.widget.*");

// Load Dojo's code relating to the Button widget
dojo.require("dojo.widget.Button");

function helloPressed()
{
// Don't forget to replace the value for 'url' with
// the value of appropriate file for your server
// (i.e. 'HelloWorldResponsePOST.asp') for an ASP server
dojo.io.bind({
url: 'HelloWorldResponseGET.jsp',
handler: helloCallback,
formNode: dojo.byId('myForm'),
mimetype: 'text/xml'
});
}

function init()
{
var helloButton = dojo.widget.byId('helloButton');
dojo.event.connect(helloButton, 'onClick', 'helloPressed')
}

dojo.addOnLoad(init);

function helloCallback(type, data, evt)
{
if (type == 'error')
{
alert('Error when retrieving data from the server!');
}
else
{
//alert(data);
var root = data.getElementsByTagName('ksdata').item(0);
var child = root.childNodes.item(0);
dojo.byId('textdata').innerHTML = child.childNodes.item(0);
//populateForm(data);
}
}

Hello World!

Please enter your name:

foo
bar
baz
thud

your response is

index.jsp:

<%
/*
' HelloWorldResponseGET.jsp
' --------
'
' Print the name that is passed in the
' 'name' GET parameter in a sentence
*/

response.setContentType("text/xml");
%>
<%=
"" +
"" +
"error" +
"You entered an invalid username." +
"" +
"" +
"" +
"Control1" +
"Text1" +
"" +
"" +
"Control2" +
"Text2" +
"" +
"" +
"Control3" +
"Text3" +
"" +
"" +
"Control4" +
"Text4" +
"" +
"" +
""
%>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gmurray71
Offline
Joined: 2003-07-31
Points: 0

Funny that you would ask. This was posted just yesterday.

http://blogs.sun.com/jenniferb/entry/more_fun_with_jmaki_getting

It shouw how to get JSON data into a Dojo combobox. Dojo widgets can support XML but it is much easier to use JSON format with them.

If you use jMaki you get much of the integration with Dojo for free as that is where we add value. This doucment will explain how to do exactly what you want from a more basic level.

https://ajax.dev.java.net/usingFaces.html