1. Prepare a JSP file First we need to prepare a JSP file which would fetch the values for our list.
Sample Code:
"GetItemDescription.jsp"
String descQuery = "SELECT distinct description FROM mtl_system_items_b WHERE organization_id = fnd_profile.value('XXQC_ITEMS_ORGANIZATION_ID') AND item_type NOT IN ('AA', 'AG')";
String query = request.getParameter("q");
Statement stmt = null;
ResultSet rset = null;
int i = 0;
WebAppsContext wctx =WebRequestUtil.validateContext(request, response);
Connection con = wctx.getJDBCConnection();
descQuery = descQuery + " AND lower(description) like '"+query+"%'";
stmt = con.createStatement ();
rset = stmt.executeQuery(descQuery);
System.out.println(descQuery);
while (rset.next() && i < 10) { String country = rset.getString(1); out.println(country); System.out.println(country); i++; } rset.close(); stmt.close();
2. Transfer jQuery files and CSS file
Copy jquery.js and jquery.autocomplete.js jQuery javascript files and jquery.autocomplete.css CSS files to $OA_HTML. These files can be found at http://jquery.com/
3. Invoke JavaScript from OAF
· Create an OARawTextBean in page to call javascript.
· Create a TextInputBean to enable list on (assuming that name of this bean is description).
· Add below code in page controller
public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
super.processRequest(pageContext, webBean);
super.processRequest(pageContext, webBean);
pageContext.putJavaScriptLibrary("jquerylib", "jquery.js");
pageContext.putJavaScriptLibrary("jqueryautolib",
"jquery.autocomplete.js");
"jquery.autocomplete.js");
OARawTextBean r = (OARawTextBean)webBean.findChildRecursive("rawText");
String javas =
"<link rel=\"stylesheet\" type=\"text/css\" href=\"css/jquery.autocomplete.css\"/> <script type=\"text/javascript\">\n" +
"$(document).ready(function(){\n" +
"$(\"#description\").autocomplete(\"GetItemDescription.jsp\");\n" +
"});\n" + "</script>\n";
r.setText(javas);
}