File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DWR error

 
srinivas lakshman
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I m new to DWR and recently wrote a program to get the values dynaically from the Server.
I get error and the page doesn load the values coming from server. Here is the code.
Any help would be greatly appreciated.


JSP Page - index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Srini DWR Page</title>
<script src="/DWRTest2/dwr/engine.js"></script>
<script type='text/javascript' src='/DWRTest2/dwr/interface/Demo.js'></script>
<script src="/DWRTest2/dwr/util.js"></script>
<script type="text/javascript">


function update() {
var name = dwr.util.getValue("demoName");
Demo.sayHello(name, function(data) {
dwr.util.setValue("demoReply", data);
});
}

function cloneSearch() {
var sel = dwr.util.getValue("selectText");
dwr.util.removeAllOptions("selectText");
dwr.util.addOptions("selectText", [ "one", "two", "three" ]);
dwr.util.setValue("selectText", sel);
}

function getModels() {
var make = dwr.util.getValue("makes");
Demo.getModels(make, function(reply) {
dwr.util.addOptions("models", reply);
});
}



</script>

</head>
<body>
<p>
Name:
<input type="text" id="demoName"/>
<input value="Send" type="button" onclick="update()"/>
<br/>
Reply: <span id="demoReply"></span>
<input type="button" value="Search" onclick="cloneSearch()"/>
<select id="selectText"></select>
<select id="makes" onchange="getModels"><option id="Aston">Aston</option><option id="BMW">BMW</option></select>
<select id="models"></select>
</body>
</html>


web.xml -

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>DWRTest2</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>



<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>


</web-app>




dwr.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://getahead.org/dwr/dwr20.dtd">

<dwr>
<allow>
<create creator="new" javascript="Demo">
<param name="class" value="com.test.Demo"/>
</create>
</allow>
</dwr>



Demo.java

package com.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo {
public String sayHello(String name) {
return "Hello, " + name;
}

public String[] cloneSearch2(){
String[] arry = new String[]{"1one","2Two","3Three"};
return arry;
}

public String[] getModels(String make){
String[] arry = new String[]{"1one","2Two","3Three"};
return arry;
}
}


 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags, and you did not say what the error is.

Eric
 
srinivas lakshman
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Apologies on that. The error is that when i select the type of Car, the drop down next to it is not getting populated from the server.
The first code snipet invloves in generating string from the server. That works. Where as from getModels() function, the values aren't getting populated.
Here is the code in the code tag. Any help is greatly appreciated.


web.xml





DWR.xml



Demo.java





index.jsp



 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic