Hello Guys if you want to add validation to the input text fields of the Criteria please follow the steps.
Step1: Create a view Criteria as shown below
Step2:
Drop this named criteria from data controls to a page as Query Panel
Step3:
Drop the View Object as form on the same page
Step4: add Partial Target of the form to Criteria
Step5: Select af:Query Component in Structure window and change the query listner property from Property Inspector as shown below(Default query Listner value is: #{bindings.EmployeesEOViewCriteriaQuery.processQuery} ) save this value which needs to be used in bean class
Step6:
write the following code in the bean class:
package com.test.beans;
import com.mobile.model.TestAMImpl;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.event.QueryEvent;
import oracle.binding.BindingContainer;
import oracle.jbo.ApplicationModule;
import oracle.jbo.server.ViewObjectImpl;
public class FormValidate1 {
public FormValidate1() {
}
public void customQueryListner(QueryEvent queryEvent) { // Add event code here...
String fname = null;
String lname = null;
BindingContext ctx = BindingContext.getCurrent();
BindingContainer cont = ctx.getCurrentBindingsEntry();
DCIteratorBinding dci = (DCIteratorBinding) cont.get("EmployeesEOView1Iterator");
ApplicationModule am = dci.getDataControl().getApplicationModule();
//ApplicationModule am = dci.getDataControl().
// cont.ge
// ApplicationModule am = dci.geta
DCDataControl dc = ctx.findDataControl("TestAMDataControl");
TestAMImpl ta =(TestAMImpl) dc.getApplicationModule();
ViewObjectImpl voi = (ViewObjectImpl)dci.getViewObject();
fname = (String)voi.getNamedWhereClauseParam("bFirstName");
lname = (String)voi.getNamedWhereClauseParam("bLastName");
if(fname.length() >4) {
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage("Name should not be lessthan 4 charecters"));
}
else if(am.getTransaction().isDirty()) {
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage("Please Save the changes or Undo Them"));
}
else{
String el = "#{bindings.EmployeesEOViewCriteriaQuery.processQuery}";
invokeEL(el, new Class[]{QueryEvent.class}, new Object[]{queryEvent});
// invokeEL(el, null, new Object[]{queryEvent});
}
}
public static Object invokeEL(String el,Class[] paramtypes, Object[] params) {
FacesContext cont = FacesContext.getCurrentInstance();
ELContext elcont = cont.getELContext();
ExpressionFactory ef = cont.getApplication().getExpressionFactory();
MethodExpression exp = ef.createMethodExpression(elcont, el, Object.class, paramtypes);
return exp.invoke(elcont, params);
}
}
Step7:
Run the application and give charecters for firstname more than 4 you will get error message.