• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help needed with DOJO and JSP

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

index.jsp:

<html>
<head>
<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">
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);
}
}


</script>
</head>

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


index.jsp:


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

response.setContentType("text/xml");
%>
<%=
"<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>" +
"</ksdata>"
%>
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is DOJO?
 
Anthony Taylor
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dojo is a framework for doing ajax and widgets. dojotoolkit.org.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
     
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The HTML forum would be most appropriate. Thusly moved.
     
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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 ]
     
    reply
      Bookmark Topic Watch Topic
    • New Topic