java - Spring MVC and jQuery Autocomplete -


i using autocomplete jquery in project, can't suggestions. when try write in text field, nothing happen !!.

here's code:

fournisseur.jsp

<div>     <input type="text" id="w-input-search" value="">     <span><button id="button-id" type="button">search</button></span>     </div>  <script type="text/javascript"> $(document).ready(function() {     $('#w-input-search').autocomplete({         serviceurl: '${pagecontext.request.contextpath}/gestionfournisseur/getfournisseur.do',         paramname: "fournisseurname",         delimiter: ",",        transformresult: function(response) {          return {                   //must convert json javascript object before process           suggestions: $.map($.parsejson(response), function(item) {                return { value: item.referencefournisseur, data: item.idfournisseur };            })           };              }       });    }); </script> 

my controller:

package com.agro.controller;  import java.util.arraylist; import java.util.date; import java.util.list;  import org.springframework.beans.factory.annotation.autowired; import org.springframework.format.annotation.datetimeformat; import org.springframework.stereotype.controller; import org.springframework.ui.modelmap; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.bind.annotation.requestparam; import org.springframework.web.bind.annotation.responsebody; import org.springframework.web.multipart.commons.commonsmultipartfile; import org.springframework.web.servlet.modelandview;  import com.agro.model.fonction; import com.agro.model.fournisseur; import com.agro.model.pays; import com.agro.model.personnecontacter; import com.agro.service.fonctionservice; import com.agro.service.fournisseurservice; import com.agro.service.paysservice; import com.agro.service.personnecontacterservice;    @controller @requestmapping(value="/gestionfournisseur") public class fournisseurcontroller {     public list<fournisseur> listefournisseur;      @autowired     paysservice paysservice;      @autowired     fournisseurservice fournisseurservice;      @autowired     fonctionservice fonctionservice;      @autowired     personnecontacterservice personnecontacterservice;        @requestmapping(value="/listefournisseur")     public string index(modelmap model){          listefournisseur= fournisseurservice.getallfournisseur();         list<pays> listepays = paysservice.getallpays();         list<fonction> listefonction = fonctionservice.getallfonction();          model.addattribute("listefourn", listefournisseur);         model.addattribute("listepays", listepays);         model.addattribute("listefonc", listefonction);         return "fournisseur";     }      @requestmapping(value="/addfournisseur", method = requestmethod.get)     public @responsebody string addfournisseur(string referencefournisseur,string raisonsocial,string adresse,string adresse2,string tel, string tel2,string fax, string mail,string  idpays,             string nomcontact,string prenomcontact,string telcontact, string mailcontact, string remarquecontact, string idfonction ){            pays py = paysservice.getpaysbyid(integer.parseint(idpays));         fonction fctn = fonctionservice.getfonctionbyid(integer.parseint(idfonction));          fournisseur fourn = new fournisseur(py, referencefournisseur, raisonsocial, adresse, adresse2, tel, tel2, fax, mail);         personnecontacter prsncontact = new personnecontacter(fctn, fourn, nomcontact, prenomcontact, telcontact, mailcontact, remarquecontact);          fournisseurservice.addfournisseur(fourn);         personnecontacterservice.addpersonnecontacter(prsncontact);          return "ok";     }          @requestmapping(value = "/getfournisseur", method = requestmethod.get)         public @responsebody list<fournisseur> getfournisseur(@requestparam string fournisseurname){             system.out.println("je suis dans getfournisseur");             list<fournisseur> result = new arraylist<fournisseur>();              for(fournisseur fourni : listefournisseur){                 if(fourni.getreferencefournisseur().contains(fournisseurname)){                     result.add(fourni);                 }             }              return result;         }  } 

pom.xml

<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">     <modelversion>4.0.0</modelversion>     <groupid>agro</groupid>     <artifactid>agro</artifactid>     <packaging>war</packaging>     <version>1.0.0-build-snapshot</version>      <properties>         <java-version>1.6</java-version>         <org.springframework-version>3.1.1.release</org.springframework-version>         <org.aspectj-version>1.6.10</org.aspectj-version>         <org.slf4j-version>1.6.6</org.slf4j-version>         <jackson.version>1.9.10</jackson.version>     </properties>        <dependencies>          <!-- spring -->         <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-context</artifactid>             <version>${org.springframework-version}</version>             <exclusions>                 <!-- exclude commons logging in favor of slf4j -->                 <exclusion>                     <groupid>commons-logging</groupid>                     <artifactid>commons-logging</artifactid>                  </exclusion>             </exclusions>         </dependency>          <dependency>   <groupid>org.springframework</groupid>    <artifactid>spring-tx</artifactid>     <version>${org.springframework-version}</version>    </dependency>   <dependency>   <groupid>org.springframework</groupid>   <artifactid>spring-orm</artifactid>  <version>${org.springframework-version}</version>  </dependency>         <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-webmvc</artifactid>             <version>${org.springframework-version}</version>         </dependency>          <dependency>         <groupid>commons-fileupload</groupid>         <artifactid>commons-fileupload</artifactid>         <version>1.2.2</version>     </dependency>      <!-- apache commons io -->     <dependency>         <groupid>org.apache.commons</groupid>         <artifactid>commons-io</artifactid>         <version>1.3.2</version>     </dependency>          <!-- aspectj -->         <dependency>             <groupid>org.aspectj</groupid>             <artifactid>aspectjrt</artifactid>             <version>${org.aspectj-version}</version>         </dependency>             <!-- logging -->         <dependency>             <groupid>org.slf4j</groupid>             <artifactid>slf4j-api</artifactid>             <version>${org.slf4j-version}</version>         </dependency>         <dependency>             <groupid>org.slf4j</groupid>             <artifactid>jcl-over-slf4j</artifactid>             <version>${org.slf4j-version}</version>             <scope>runtime</scope>         </dependency>         <dependency>             <groupid>org.slf4j</groupid>             <artifactid>slf4j-log4j12</artifactid>             <version>${org.slf4j-version}</version>             <scope>runtime</scope>         </dependency>         <dependency>             <groupid>log4j</groupid>             <artifactid>log4j</artifactid>             <version>1.2.15</version>             <exclusions>                 <exclusion>                     <groupid>javax.mail</groupid>                     <artifactid>mail</artifactid>                 </exclusion>                 <exclusion>                     <groupid>javax.jms</groupid>                     <artifactid>jms</artifactid>                 </exclusion>                 <exclusion>                     <groupid>com.sun.jdmk</groupid>                     <artifactid>jmxtools</artifactid>                 </exclusion>                 <exclusion>                     <groupid>com.sun.jmx</groupid>                     <artifactid>jmxri</artifactid>                 </exclusion>             </exclusions>             <scope>runtime</scope>         </dependency>          <!-- @inject -->         <dependency>             <groupid>javax.inject</groupid>             <artifactid>javax.inject</artifactid>             <version>1</version>         </dependency>          <!-- servlet -->         <dependency>             <groupid>javax.servlet</groupid>             <artifactid>servlet-api</artifactid>             <version>2.5</version>             <scope>provided</scope>         </dependency>         <dependency>             <groupid>javax.servlet.jsp</groupid>             <artifactid>jsp-api</artifactid>             <version>2.1</version>             <scope>provided</scope>         </dependency>         <dependency>             <groupid>javax.servlet</groupid>             <artifactid>jstl</artifactid>             <version>1.2</version>         </dependency>          <!-- base de donnee -->         <dependency>             <groupid>mysql</groupid>             <artifactid>mysql-connector-java</artifactid>             <version>5.1.17</version>         </dependency>         <dependency>             <groupid>org.hibernate</groupid>             <artifactid>hibernate-entitymanager</artifactid>             <version>3.6.5.final</version>         </dependency>          <!-- need @configuration -->         <dependency>             <groupid>cglib</groupid>             <artifactid>cglib</artifactid>             <version>2.2.2</version>         </dependency>         <!-- jackson -->         <dependency>             <groupid>org.codehaus.jackson</groupid>             <artifactid>jackson-mapper-asl</artifactid>             <version>${jackson.version}</version>         </dependency>         <!-- test -->         <dependency>             <groupid>junit</groupid>             <artifactid>junit</artifactid>             <version>4.7</version>             <scope>test</scope>         </dependency>             </dependencies>     <build>         <plugins>             <plugin>                 <artifactid>maven-eclipse-plugin</artifactid>                 <version>2.9</version>                 <configuration>                     <additionalprojectnatures>                         <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>                     </additionalprojectnatures>                     <additionalbuildcommands>                         <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>                     </additionalbuildcommands>                     <downloadsources>true</downloadsources>                     <downloadjavadocs>true</downloadjavadocs>                 </configuration>             </plugin>             <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-compiler-plugin</artifactid>                 <version>2.5.1</version>                 <configuration>                     <source>1.6</source>                     <target>1.6</target>                     <compilerargument>-xlint:all</compilerargument>                     <showwarnings>true</showwarnings>                     <showdeprecation>true</showdeprecation>                 </configuration>             </plugin>             <plugin>                 <groupid>org.codehaus.mojo</groupid>                 <artifactid>exec-maven-plugin</artifactid>                 <version>1.2.1</version>                 <configuration>                     <mainclass>org.test.int1.main</mainclass>                 </configuration>             </plugin>         </plugins>     </build> </project> 

please, tell how works ? thanks!

${pagecontext.request.contextpath}/gestionfournisseur/getfournisseur.do 

you don't have handler mapping getfournisseur.do getfournisseur. rid of .do , should work.


Comments