Thursday, October 25, 2012

How to Implement Auto Suggestion using ADF ?

How to Implement Auto Suggestion using ADF ?





----------------------------------------------------------------------------
    public List onSuggest(String string) {
       
        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("setSearchCriteria");
        setVariable.getParamsMap().put("value", string);
        setVariable.execute();    
       
        //the data in the suggest list is queried by a tree binding.
       
        JUCtrlHierBinding hierBinding = (JUCtrlHierBinding) bindings.get("CountriesLookup1");     
        //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 displayDataList = hierBinding.getRangeSet();     
       
        ArrayList selectItems = new ArrayList();
       
        for (JUCtrlValueBindingRef displayData : displayDataList){
          Row rw = displayData.getRow();
          selectItems.add(new SelectItem((String)rw.getAttribute("LocName"),(String)rw.getAttribute("LocName")));
        }
       
        return selectItems;
    } 

------------------------------------------------------------------------
                
           

------------------------------------------------------------------------








---------------------------------------------------------------------------

Create a Read Only VO CountriesLookup.

Query : SELECT distinct(loc_name) FROM country.
Bind Variable :     Name="SearchCriteria"
    Kind="viewcriteria"
    Type="java.lang.String"/>


View Criteria :
    Name="CountriesLookupCriteria"
    ViewObjectName="neelmani.model.queries.CountriesLookup"
    Conjunction="AND">
   
     
                  Name="displayOperators"
          Value="InAdvancedMode"/>
                  Name="autoExecute"
          Value="false"/>
                  Name="allowConjunctionOverride"
          Value="true"/>
                  Name="showInList"
          Value="true"/>
                  Name="mode"
          Value="Basic"/>
     

   

          Name="vcrow39"
      UpperColumns="1">
              Name="CountriesLookupCriteria_vcrow39_LocName"
        ViewAttribute="LocName"
        Operator="STARTSWITH"
        Conjunction="AND"
        Value=":SearchCriteria"
        IsBindVarValue="true"
        Required="Optional"/>
   

 


---------------------------------------------------------
Put the bellow code in CountriesLookupImpl.(countriedLookup View Object)

    /**
     * Returns the variable value for SearchCriteria.
     * @return variable value for SearchCriteria
     */
    public String getSearchCriteria() {
        return (String)ensureVariableManager().getVariableValue("SearchCriteria");
    }

    /**
     * Sets value for variable SearchCriteria.
     * @param value value to bind as SearchCriteria
     */
    public void setSearchCriteria(String value) {
        ensureVariableManager().setVariableValue("SearchCriteria", value);
    }

--
Select and sattle right the  setSearchCriteria from Client Interface of View Object.