In OAF - We have a bean called : QueryBean - which performs Automatic Search Functionality.
There are use cases where we do customization to the Standard Query bean.
Similarly in ADF too, there is search bean and also it provides custom logic to be implemented.
The Same is explained in this tutorial in detailed manner @
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/30-table-filter-queries-169172.pdf
Java Logic Used is mentioned below : EmployeeQueryPG.java
package view.backing;
import java.util.Map;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.faces.context.FacesContext;
import oracle.adf.view.rich.component.rich.RichDocument;
import oracle.adf.view.rich.component.rich.RichForm;
import oracle.adf.view.rich.component.rich.data.RichTable;
import oracle.adf.view.rich.component.rich.input.RichInputDate;
import oracle.adf.view.rich.component.rich.output.RichMessages;
import oracle.adf.view.rich.event.QueryEvent;
import oracle.adf.view.rich.model.FilterableQueryDescriptor;
public class EmployeeQueryPG {
private RichForm f1;
private RichDocument d1;
private RichMessages m1;
private RichTable t1;
private RichInputDate id1;
public void setF1(RichForm f1) {
this.f1 = f1;
}
public RichForm getF1() {
return f1;
}
public void setD1(RichDocument d1) {
this.d1 = d1;
}
public RichDocument getD1() {
return d1;
}
public void setM1(RichMessages m1) {
this.m1 = m1;
}
public RichMessages getM1() {
return m1;
}
public void setT1(RichTable t1) {
this.t1 = t1;
}
public RichTable getT1() {
return t1;
}
public void setId1(RichInputDate id1) {
this.id1 = id1;
}
public RichInputDate getId1() {
return id1;
}
public void onQuery(QueryEvent queryEvent) {
// Add event code here...
System.out.println("user is searching");
// pre-processing code here
boolean invokeQuery = true;
/*
* Method called by the Query Listener. This method checks if
* the DepartmentId parameter contains a valid number and puts
* the DepartmentName into the expected case
*/
FilterableQueryDescriptor fqd =
(FilterableQueryDescriptor)
queryEvent.getDescriptor();
Map map = fqd.getFilterCriteria();
// ensure DepartmentId contains a Number
String EmployeeId = (String) map.get("EmployeeId");
System.out.println("entered EmployeeId-->" + EmployeeId);
if (EmployeeId != null && EmployeeId.length()>0){
try {
// try to parse String to integer
Long.parseLong(EmployeeId);
} catch (Exception ex) {
// not a string
System.out.println("Not a string");
// add some error message here
// unset selection
map.remove("DepartmentId");
invokeQuery = false;
}
}
// ensure the initial character is in uppercase
String departmentName = (String) map.get("FirstName");
if (departmentName != null && departmentName.length()>0){
StringBuffer sbuf = new StringBuffer();
sbuf.append(departmentName.substring(0,1).toUpperCase());
sbuf.append(departmentName.substring(1).toLowerCase());
map.put("FirstName",sbuf.toString());
}
if (invokeQuery) {
invokeMethodExpression("#{bindings.EmployeeEOVO1Query.processQuery}",
Object.class,QueryEvent.class,
queryEvent);
}
}
public Object invokeMethodExpression(String expr, Class returnType, Class[] argTypes,Object[] args){
FacesContext fc = FacesContext.getCurrentInstance();
ELContext elctx = fc.getELContext();
ExpressionFactory elFactory = fc.getApplication().getExpressionFactory();
MethodExpression methodExpr = elFactory.createMethodExpression(elctx,expr,returnType,argTypes);
return methodExpr.invoke(elctx,args);
}
public Object invokeMethodExpression(String expr, Class returnType,Class argType, Object argument){
return invokeMethodExpression(expr, returnType,new Class[]{argType}, new Object[]{argument});
}
}