• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Help needed with DOJO and JSP

Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'. Also, could somene point me in the direction of some good examples of using jsp with dojo? Here is my code:


<title>Dojo: Hello World!</title>

<!-- SECTION 1 -->
<script type="text/javascript" src="js/dojo/dojo.js"></script>
<script type="text/javascript" src="js/dojo/kstools.js"></script>
<script type="text/javascript">

// Load Dojo's code relating to widget managing functions

// Load Dojo's code relating to the Button widget

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
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')


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


<button dojoType="Button" widgetId="helloButton" toggle="explode" toggleDuration="250">Hello World!</button>
<form id="myForm" method="POST">
Please enter your name: <input type="text" name="name">
<select dojoType="combobox">
<option value="foo">foo</option>
<option value="bar">bar</option>
<option value="baz">baz</option>
<option value="thud">thud</option>
your response is <span id="textdata"></span>


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

"<ksdata>" +
"<message>" +
"<type>error</type>" +
"<text>You entered an invalid username.</text>" +
"</message>" +
"<values>" +
"<value>" +
"<name>Control1</name>" +
"<text>Text1</text>" +
"</value>" +
"<value>" +
"<name>Control2</name>" +
"<text>Text2</text>" +
"</value>" +
"<value>" +
"<name>Control3</name>" +
"<text>Text3</text>" +
"</value>" +
"<value>" +
"<name>Control4</name>" +
"<text>Text4</text>" +
"</value>" +
"</values>" +
Anthony Taylor
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dojo is a framework for doing ajax and widgets. dojotoolkit.org.
Ben Souther
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't seem to be JSP related to me.

We have
  • HTML/Javascript
  • Java Server Faces
  • Other Frameworks

  • I'm guessing the HTML/Javascript forum will be your best bet for this question. Let me know where you would like it moved.
    Also, a readonly copy of this thread will stay in this forum.
    [ January 07, 2007: Message edited by: Ben Souther ]
    Posts: 67496
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The HTML forum would be most appropriate. Thusly moved.
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Not sure whether this will help with your larger problem of getting an error when you make the request, but most of the things that I have read about Dojo say that you should have your dojo.require() statements all in a separate block of script from the actual functions, like this:

    As far as debugging the error that you're getting, nothing is really jumping out at me as being incorrect about your code. This is probably a silly suggestion on my part, but are you certain that the Ajax call is getting to the proper JSP on the server? If so, then I'd recommend putting some extra code in the JSP to see what exactly it is sending back, and putting some code in your handler method in the Javascript to actually see what is in the type, data, and evt variables (especially type and data). This might help give you some clues as to what's going wrong and where.
    [ January 08, 2007: Message edited by: Joel Jorgensen ]
      Bookmark Topic Watch Topic
    • New Topic