autocomplete – dwr

Tags

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"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>autocomplete</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Dwr</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>Dwr</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 3.0//EN" "http://directwebremoting.org/schema/dwr30.dtd">
<dwr>
  <allow>
    <create creator="new" javascript="dwrMgr">
      <param name="class" value="com.faisal.dwr.manager.DwrManager"></param>
    </create>
  </allow>
</dwr>

 

 

DwrManager::

package com.faisal.dwr.manager;

import java.util.ArrayList;
import java.util.List;

public class DwrManager
{
    public List<String> getWords( String input )
    {
        List<String> words = new ArrayList<String>();
        words.add( "this" );
        words.add( "is a" );
        words.add( input );
        return words;
    }
}

 

 

index.jsp::

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Autocomplete will be here</title>
<link rel="stylesheet" href="css/jquery-ui-1.11.4.css">
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/interface/dwrMgr.js'></script>
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.11.4.js"></script>
</head>
<body>
  <label>Word: </label>
  <input type="text" class="autocomplete">
  <script type="text/javascript">
            $( function(){
                $( '.autocomplete' ).autocomplete( {
                    minLength : 1, source : function( request, response ){
                        var input = request.term;
                        dwrMgr.getWords( input, function( list ){
                            console.log( list );
                            response( list );
                        } );
                    }
                } );
            } );
        </script>
</body>
</html>

 

Follow

Get every new post delivered to your Inbox.

Join 324 other followers