How-to dynamically filter model-driven LOV
- by Frank Nimphius
Normal
0
false
false
false
EN-US
X-NONE
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
Often developers need to filter a LOV query with information obtained
from an ADF Faces form or other where. The sample below shows how to define a launch popup listener configured on the launchPopupListener property of the af:inputListOfValues component
to filter a list of values.
<af:inputListOfValues id="departmentIdId"
value="#{bindings.DepartmentId.inputValue}"
model="#{bindings.DepartmentId.listOfValuesModel}"
launchPopupListener="#{PopupLauncher.onPopupLaunch}" … >
…
</af:inputListOfValues>
A list of values is queried using a search binding that gets created in
the PageDef file of a view when a lis of value component gets added. The
managed bean code below looks this search binding up to then add a view
criteria that filters the query.
Note: There is no public API yet
available for the FacesCtrlLOVBinding
class, which is
why I use the internal package class it in the example.
public void onPopupLaunch(LaunchPopupEvent launchPopupEvent) {
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
FacesCtrlLOVBinding lov =
(FacesCtrlLOVBinding)bindings.get("DepartmentId");
ViewCriteriaManager vcm =
lov.getListIterBinding().getViewObject().getViewCriteriaManager();
//make sure the view criteria is cleared
vcm.removeViewCriteria(vcm.DFLT_VIEW_CRITERIA_NAME);
//create a new view criteria
ViewCriteria vc =
new ViewCriteria(lov.getListIterBinding().getViewObject());
//use the default view criteria name
//"__DefaultViewCriteria__"
vc.setName(vcm.DFLT_VIEW_CRITERIA_NAME);
//create a view criteria row for all queryable attributes
ViewCriteriaRow vcr = new ViewCriteriaRow(vc);
//for this sample I set the query filter to DepartmentId 60.
//You may determine it at runtime by reading it from a managed bean
//or binding layer
vcr.setAttribute("DepartmentId", 60);
//also note that the view criteria row consists of all attributes
//that belong to the LOV list view object, which means that you can
//filter on multiple attributes
vc.addRow(vcr);
lov.getListIterBinding().getViewObject().applyViewCriteria(vc);
}
Note: Instead of using the vcm.DFLT_VIEW_CRITERIA_NAME name you can also define a custom name for the
view criteria.