Hi ,
I want to use dwr with struts.
I follow the following procedure.
Step 1:Add the dwr servlet entries in web.xml
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR Servlet</display-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
also added for struts servlet
<load-on-startup>2</load-on-startup>
so that it get initialize first.
Step 2: create the simple jsp page with name Login.jsp
<%@taglib prefix="html" uri="/WEB-INF/struts-html.tld"%>
<script type='text/javascript' src='../dwr/engine.js'> </script>
<script type='text/javascript' src='../dwr/util.js'> </script>
<script type='text/javascript' src='../dwr/interface/login.js'> </script>
<html:form action="LoginForm" method="post">
Username <html:text property="username onchange="hello()"/>
Reply:
Password <html:password property="password"/>
<html:submit></html:submit>
<html:reset></html:reset>
</html:form>
Step 3: create the Struts Form with name Loginform in the package com.dwr
package com.dwr;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm {
private String username;
private String password;
public String sayHello(String name)
{
return "Hello, you have entered the value: " + name;
}
//Along getters and setters for username, password
Step 4: create the javascript code with the name login.js
function hello(){
var name = dwr.util.getValue("username");
LoginForm.sayHello(name, function(data) {
dwr.util.setValue("usernameReply", data);
});
}
Step 5: create the dwr.xml with the following entries
<?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>
<convert converter="bean" match="com.dwr.LoginForm"/>
<create creator="struts" javascript=" com.dwr.LoginForm">
<include method="sayHello"/>
</create>
</allow>
</dwr>
Step 6: Add the following entries in Struts-config.xml
<form-beans>
<form-bean name="LoginForm" type="com.dwr.LoginForm"/>
</form-beans>
</action-mappings>
<action path="/LoginForm" parameter=" Login.jsp" type="org.apache.struts.actions.ForwardAction"/>
</action-mappings>
But still I am getting errors in the creation of form bean.
Can anyone guide me for the integration of Struts with dwr while taking all steps to be followed.