How To Apply View Criteria Programmatically
Assume we have Departments ViewObject Contains the Attributes ( DepartmentName, DepartmentId, LocationId, ManagerId ) .
but we need to filter Departments ViewObject based on ManagerId . So we need to the following steps:
4- add the class Parameter to Your Application
public class Parameter {
private String attributeName;
private Object value;
public Parameter(String attributeName ,Object value) {
super();
setAttributeName(attributeName);
setValue(value);
}
5- add the following Function to your Code
public static void applyViewCriteria(ViewObject vo , String criteriaName , Parameter[]params) {
if(vo!=null) {
ViewObjectImpl voImpl = (ViewObjectImpl)vo;
voImpl.setApplyViewCriteriaName(criteriaName);
if(params!=null) {
for (Parameter parameter : params) {
voImpl.setNamedWhereClauseParam(parameter.getAttributeName(),parameter.getValue());
}
}
vo.setRangeSize(-1);
vo.executeQuery();
}
}
6- Finally , Remember that we named The Criteria "ManagerCriteria " and we have a bind Variable named "ManagerVar ". and The Name of ViewObject Instance is "DepartmentsView1" .
ViewObject voDepartments = ADFUtils.getAm().getDepartmentsView1();
Parameter[] paramArray = new Parameter[1];
paramArray[0]=new Parameter("ManagerVar",100);
applyViewCriteria(voDepartments, "ManagerCriteria", paramArray);
7- The ViewObject instance "DepartmentsView1" is Filtered now where MangerId = 100;
8 -Thanks.
Assume we have Departments ViewObject Contains the Attributes ( DepartmentName, DepartmentId, LocationId, ManagerId ) .
but we need to filter Departments ViewObject based on ManagerId . So we need to the following steps:
- Add View Criteria To Departments ViewObject and name it ManagerCriteria
- Add item ManagerId .
- Add Bind Variable and name it ManagerVar and make sure it is not required .
4- add the class Parameter to Your Application
public class Parameter {
private String attributeName;
private Object value;
public Parameter(String attributeName ,Object value) {
super();
setAttributeName(attributeName);
setValue(value);
}
5- add the following Function to your Code
public static void applyViewCriteria(ViewObject vo , String criteriaName , Parameter[]params) {
if(vo!=null) {
ViewObjectImpl voImpl = (ViewObjectImpl)vo;
voImpl.setApplyViewCriteriaName(criteriaName);
if(params!=null) {
for (Parameter parameter : params) {
voImpl.setNamedWhereClauseParam(parameter.getAttributeName(),parameter.getValue());
}
}
vo.setRangeSize(-1);
vo.executeQuery();
}
}
6- Finally , Remember that we named The Criteria "ManagerCriteria " and we have a bind Variable named "ManagerVar ". and The Name of ViewObject Instance is "DepartmentsView1" .
ViewObject voDepartments = ADFUtils.getAm().getDepartmentsView1();
Parameter[] paramArray = new Parameter[1];
paramArray[0]=new Parameter("ManagerVar",100);
applyViewCriteria(voDepartments, "ManagerCriteria", paramArray);
7- The ViewObject instance "DepartmentsView1" is Filtered now where MangerId = 100;
8 -Thanks.

