Sometimes we may come across a situation where we want to have a field in Search Component in UI but don't want the corresponding view criteria item to be part of the where clause generated for the ViewObject. This requirement generally comes when the value set for the search field in UI is used to decide which custom where condition to be added instead of the search field itself.
This requirement makes more sense when a ViewObject is read-only based on a sql query and you want the query execution mode for the ViewCriteria to be Database.
You need to override the getCriteriaItemClause() method of the ViwObject
The below code snippet looks for the search field "ManagerOnly" which has two possible values "Y"/"N". If the Value is "Y", a custom where condition has to be returned else nothing, which means there won't be any clause generated for the corresponding criteria item.
(Assumption: There is Emp schema where Emp details are stored in Employee table. Manager is highest in hierarchy and the manager_id value for manager will be its own employee id.)
@Override
public String getCriteriaItemClause(ViewCriteriaItem vci) {
if (vci.getAttributeDef().getName().equals("ManagerOnly") && vci.getViewCriteria().getName().contains("MyEmpViewCriteria")&& vci.getValue().equals("Y")) {
return "EMPLOYEE_ID=MANAGER_ID";
} else { //If the attribute is not "ManagerOnly" retain the default behavior.
return super.getCriteriaItemClause(vci);
}
}
This requirement makes more sense when a ViewObject is read-only based on a sql query and you want the query execution mode for the ViewCriteria to be Database.
You need to override the getCriteriaItemClause() method of the ViwObject
The below code snippet looks for the search field "ManagerOnly" which has two possible values "Y"/"N". If the Value is "Y", a custom where condition has to be returned else nothing, which means there won't be any clause generated for the corresponding criteria item.
(Assumption: There is Emp schema where Emp details are stored in Employee table. Manager is highest in hierarchy and the manager_id value for manager will be its own employee id.)
@Override
public String getCriteriaItemClause(ViewCriteriaItem vci) {
if (vci.getAttributeDef().getName().equals("ManagerOnly") && vci.getViewCriteria().getName().contains("MyEmpViewCriteria")&& vci.getValue().equals("Y")) {
return "EMPLOYEE_ID=MANAGER_ID";
} else { //If the attribute is not "ManagerOnly" retain the default behavior.
return super.getCriteriaItemClause(vci);
}
}
in which file do i need to override the getCriteriaItemClause() ?
ReplyDeleteIn your ViewObjectImpl file
ReplyDelete