Sample

View: New views
4 Messages — Rating Filter:   Alert me  

Sample

by Pushpa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am new to DWR.

I have written a sample that calls a java method

HTML page

<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type='text/javascript' src='../tabs/tabs.js'> </script>
        <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/Demo.js'> </script>
        <script type="text/javascript" src='../js/mytext.js'> </script>
        <link rel="stylesheet" type="text/css" href="../tabs/tabs.css" />
        <link rel="stylesheet" type="text/css" href="../generic.css" />
               
    </head>
    <body onload="dwr.util.useLoadingMessage();dwr.engine.setActiveReverseAjax(true);">
        <input type="text" name="myName" value="">
        <input type="button" value="Greet!!" onclick="greet();"><br>
         Reply:
       
    </body>
</html>


mytext.js

function greet(){
    var name = dwr.util.getValue("myName");
    SimpleText.sayHello(name, function(data){
        dwr.util.setValue("greetReply", data);
    });
}

SimpleText.java

package org.mydwr.examples.text;

/**
 *
 * @author Pushpa
 */
public class SimpleText
{
    /**
     * Return a server side string to display on the client in real time
     * @param name The name of person to say hello to
     * @return A demo string
     */
    public String sayHello(String name)
    {
        return "Hello, " + name;
    }
}


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="SimpleText">
   
    </create>
   </allow>
</dwr>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="dwr">
    <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>
        <init-param>
            <param-name>pollAndCometEnabled</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dwr-invoker</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>


When i run this , the SimpleText class is not recognised in the JS file.

Can anyone tell me what is wrong with my code ??

Re: Sample

by David Marginian-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You need to include the interface file:

<script type='text/javascript' src='../dwr/interface/SimpleText.js/>



Pushpa wrote:

> I am new to DWR.
>
> I have written a sample that calls a java method
>
> HTML page
>
> <html>
>     <head>
>         <title></title>
>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
>         <script type='text/javascript' src='../tabs/tabs.js'> </script>
>         <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/Demo.js'>
> </script>
>         <script type="text/javascript" src='../js/mytext.js'> </script>
>         <link rel="stylesheet" type="text/css" href="../tabs/tabs.css" />
>         <link rel="stylesheet" type="text/css" href="../generic.css" />
>                
>     </head>
>     <body
> onload="dwr.util.useLoadingMessage();dwr.engine.setActiveReverseAjax(true);">
>         <input type="text" name="myName" value="">
>         <input type="button" value="Greet!!" onclick="greet();"><br>
>          Reply:
>        
>     </body>
> </html>
>
>
> mytext.js
>
> function greet(){
>     var name = dwr.util.getValue("myName");
>     SimpleText.sayHello(name, function(data){
>         dwr.util.setValue("greetReply", data);
>     });
> }
>
> SimpleText.java
>
> package org.mydwr.examples.text;
>
> /**
>  *
>  * @author Pushpa
>  */
> public class SimpleText
> {
>     /**
>      * Return a server side string to display on the client in real time
>      * @param name The name of person to say hello to
>      * @return A demo string
>      */
>     public String sayHello(String name)
>     {
>         return "Hello, " + name;
>     }
> }
>
>
> 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="SimpleText">
>    
>     </create>
>    </allow>
> </dwr>
>
>
> web.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="dwr">
>     <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>
>         <init-param>
>             <param-name>pollAndCometEnabled</param-name>
>             <param-value>true</param-value>
>         </init-param>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>dwr-invoker</servlet-name>
>         <url-pattern>/dwr/*</url-pattern>
>     </servlet-mapping>
>     <session-config>
>         <session-timeout>
>             30
>         </session-timeout>
>     </session-config>
>     <welcome-file-list>
>         <welcome-file>index.jsp</welcome-file>
>     </welcome-file-list>
> </web-app>
>
>
> When i run this , the SimpleText class is not recognised in the JS file.
>
> Can anyone tell me what is wrong with my code ??
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Sample

by Pushpa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It worked .... thanks a lot.

After reading about DWR, i understood that DWR is used to call the java methods from javascript. Is there anything else that we can do using DWR ??
Can you please tell me where can i find good examples ??





You need to include the interface file:

<script type='text/javascript' src='../dwr/interface/SimpleText.js/>




Re: Sample

by David Marginian-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There are many examples in the war file.  Download the war and go
through the examples.  There is also a lot of information on the website.

Pushpa wrote:

> It worked .... thanks a lot.
>
> After reading about DWR, i understood that DWR is used to call the java
> methods from javascript. Is there anything else that we can do using DWR ??
> Can you please tell me where can i find good examples ??
>
>
>
>
>
> You need to include the interface file:
>
> <script type='text/javascript' src='../dwr/interface/SimpleText.js/>
>
>
>
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

LightInTheBox - Buy quality products at wholesale price