Wednesday, 16 October 2013

Oracle applications business suite version 12.1 has many rich user interface components and features. One of them is look ahead list of values or auto complete feature. There are requirements from many clients to implement the same but if these clients are on older versions of oracle applications, it is not possible to have these features without upgrading the complete technology stack. In this document we explain how to achieve this feature using AJAX technology with older version of OAF (Oracle Application Framework)

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);

        pageContext.putJavaScriptLibrary("jquerylib", "jquery.js");
        pageContext.putJavaScriptLibrary("jqueryautolib",
                                         "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);
    }