i am trying to make an autocomplete box using yahoo libraries. trying to fill the list of data from database . framework is spring & hibernate. can anyone help me out with this?
Autocomplete
Collapse
X
-
-
Please have a look into my code
Code:<div id="myAutoComplete"> <input type="text" name="quickAddInput" id="quickAddInput" class="input" > <div id="autoCompleteContainer"></div> </div> <script type="text/javascript"> // An XHR DataSource var mySchema = ["ResultSet.Result", "PartNo"]; var myDataSource = new YAHOO.widget.DS_XHR("http://156.150.107.223:8080/eagle/ncdetail.do", mySchema); myDataSource.scriptQueryAppend = "method=getPartNos"; var myAutoComp = new YAHOO.widget.AutoComplete("quickAddInput","autoCompleteContainer", myDataSource); myAutoComp.prehighlightClassName = "yui-ac-prehighlight"; // Display up to 10 results in the container myAutoComp.maxResultsDisplayed = 10 // Require user to type at least 1 characters before triggering a query myAutoComp.minQueryLength = 2 ; // Enable a drop-shadow under the container element myAutoComp.useShadow = true; myAutoComp.autoHighlight = false; // Define a custom formatter function var fnCustomFormatter = function(oResultItem, sQuery) { var sKey = oResultItem[0]; var aMarkup = ["<div class='sample-result'><span class='sample-key'>", sKey,"</span></div>"]; return (aMarkup.join("")); }; myAutoComp.formatResult = this.fnCustomFormatter; </script>
and this is the function which returns the list of values:
Code:public ActionForward getPartNos(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) { ArrayList partNos = new ArrayList(); ItemMasterVo itVo=new ItemMasterVo(); String ptNos = ""; String result = ""; result = result + "{\"ResultSet\":{\"Result\":[ "; try{ partNos=(ArrayList)itemManager.getItemMasters(); ServletOutputStream out = response.getOutputStream(); int i=0; if (partNos != null) { Iterator it = partNos.iterator(); while (it.hasNext()) { itVo = (ItemMasterVo) it.next(); result = result + "{\"PartNo\":" + "\"" + itVo.getStrItemNo() + "\"}"; if (i < partNos.size() -1 ) result = result + ","; i++; } } out.println(result); out.flush(); out.close(); } catch(Exception e){ System.out.println("exception " + e.getMessage()); } return null; }
.Values are not displaying in the jsp page and it shows a javascript error 'Exception thrown and not caught'.
Do u have any idea what is the problem?Comment
-
That suggests that there may be a problem in the JSP code. Try a simple data set first (e.g. a simple local array data source) and see if the autocomplete works with that.Comment
-
Comment