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:
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.