Wednesday, July 31, 2013

Auto Suggestion lov ADF




Here is a simple example on how to achieve an Auto Suggestion LOV for input text box or input text box with list of values using Auto Suggest Behavior





  • Add a tree structure(Employees1LookupView1) and action(ExecuteWithParams) to the bindings of the page- these are referenced from the managedBean ->SelectListBean


     <af:inputText
                        label="#{bindings.LastName1.hints.label}"
                        required="#{bindings.LastName1.hints.mandatory}"
                        columns="#{bindings.LastName1.hints.displayWidth}"
                        maximumLength="#{bindings.LastName1.hints.precision}"
                        shortDesc="#{bindings.LastName1.hints.tooltip}"
                        id="it10" autoSubmit="true">
            <f:validator binding="#{bindings.LastName1.validator}"/>
            <af:autoSuggestBehavior maxSuggestedItems="10"
                                    suggestedItems="#{viewScope.SelectListBean.onCitySuggest}"/>
          </af:inputText>

 
 // method in a managed bean

//searchLastName is from the entered text field 

public List onCitySuggest(String searchLastName) {
    ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();

    System.out.println(searchLastName);
    //get access to the binding context and binding container at runtime
    BindingContext bctx = BindingContext.getCurrent();
    BindingContainer bindings = bctx.getCurrentBindingsEntry();
    //set the bind variable value that is used to filter the View Object
    //query of the suggest list. The View Object instance has a View
    //Criteria assigned
    OperationBinding setVariable = (OperationBinding) bindings.get("ExecuteWithParams");
    setVariable.getParamsMap().put("BindName", searchCityName);
    setVariable.execute();
    //the data in the suggest list is queried by a tree binding.
    JUCtrlHierBinding hierBinding = (JUCtrlHierBinding) bindings.get("Employees1LookupView1");


    //re-query the list based on the new bind variable values
    hierBinding.executeQuery();

    //The rangeSet, the list of queries entries, is of type
    //JUCtrlValueBndingRef.
    List<JUCtrlValueBindingRef> displayDataList = hierBinding.getRangeSet();

    for (JUCtrlValueBindingRef displayData : displayDataList){
    Row rw = displayData.getRow();
    //populate the SelectItem list
    //new SelectItem(DateValue(value set to database), ListValue(list of values displayed));
    selectItems.add(new SelectItem(
    (String)rw.getAttribute("LastName"),
    (String)rw.getAttribute("LastName")));
    }

    return selectItems;
    }


 Query

SELECT Employees1Lookup.EMPLOYEE_ID,
       Employees1Lookup.FIRST_NAME,
       Employees1Lookup.LAST_NAME,
       Employees1Lookup.EMAIL,
       Employees1Lookup.PHONE_NUMBER,
       Employees1Lookup.HIRE_DATE,
       Employees1Lookup.JOB_ID,
       Employees1Lookup.SALARY,
       Employees1Lookup.COMMISSION_PCT,
       Employees1Lookup.MANAGER_ID,
       Employees1Lookup.DEPARTMENT_ID
FROM EMPLOYEES Employees1Lookup

WHERE ( (UPPER(Employees1Lookup.LAST_NAME) LIKE UPPER('%' || :BindName || '%') ) )

click this to download sample

Reference: https://blogs.oracle.com/adf/entry/how_to_create_cascading_depending

http://www.oracle.com/technetwork/developer-tools/jdev/autosuggest-090094.html

No comments: