Spring 3, ldap and Query autocomplete text field

2019-08-22 14:32发布

I would like to have an autocompliting input (text) field on my Spring 3 form. The suggested values should come from ldap. I should use JQuery for this, but so far that's all I know. I have found some examples with data txt.files, but not ldap.

1条回答
Fickle 薄情
2楼-- · 2019-08-22 15:04

Create a Servlet or Controller (for example /getLdapData) which will fetch data from data base and return it as string when '\n' will be separator between values:

Then create autocomplete for your control:

<script type="text/javascript">
    $(document).ready(function(){
        $("#ldapSearch").autocomplete('/getLdapData');
    });      
  </script>

Updated:

 @RequestMapping(value ="/getLdapData",method= RequestMethod.GET)
 @ResponseBody
 public void getMaxRequestSize(HttpServletResponse response){
 String autoCompleteList = null;
 //List<String> ldapUsers is the list you fetched from LDAP.
 ldapUsers = ldapService.getUserList();
 Iterator itr = ldapUsers.iterator(); 
     while(itr.hasNext()) {
     autoCompleteList +=itr.next().toString() + "\n" ; 
     }         

 response.setContentType("text/html");
     PrintWriter writer;
    try {
        writer = response.getWriter(); 
        writer.write(autoCompleteList);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     }

I don't know exactly how to get the list of users from LDAP, but I think this article can give you right direction.

查看更多
登录 后发表回答