http://forums.oracle.com/forums/thread.jspa?threadID=2157132&tstart=30
Problem Statement :
LOVs in ADF match the entered value using a LIKE operation. For example, let's say we have an attribute of type String with an associated LOV. When entering the value 'V', even if the value 'V' exists, the LOV will open and show values matching 'V%' ('V', 'Va', 'Vb'...).
Is there any chance to prevent the LOV opening when the exact match exists?
I have prepared sample for achieving the same. In my sample i have taken DepartmentId in Employee Master.
In the XE data there will be data
Department Id : 10(Adminstration),100(Finance)...
In the regular LOV when the user types 10 even though exact match of 10 is there lov popup opens.
one of the problem statement in the below OTN url
http://forums.oracle.com/forums/thread.jspa?messageID=9203960
But prepared a generic code for LOV launch which will work both for Number datatype as well as Varchar Datatype.
Solution:
The base concept of the solution is in the LaunchPopupListener's LaunchPopupEvent where there is a provision to set the Launch i.e launchPopupEvent.setLaunch(false) and there is a method to check launchPopupEvent.isLaunchPopup(). with the two methods we can control the launching of the popup.
Then we need to identify whether user entered value matching with the records filtered. For this we need to get the JUCtrlListBinding's ListIterator where we can get the LOV iterator, in that we can check whether the entered value is having exact match in the iterator, if exact match found then we need to queue the return popup listener with the lauchpopupevent set launch to false.
Note: If the generic launchpopup is used for Varchar attributes. Then the LOV ViewObject should have Orderby clause.
Below the code snippet for the generic launchpopup. Where we can call in the Listofvalues Launchpopup listener.Download Link: Sample For Exact Match LOV
public void lovcustomLaunch(LaunchPopupEvent launchPopupEvent) { String currentColumnName = null; String valueExpression = null; JUCtrlListBinding ctrlListBinding = null; ViewObject baseViewObject = null; AttributeDef lovAttributeDef = null; AttributeDef lovlistAttributeDef = null; ListBindingDef listBindingDef = null; String[] listAttributeNames = null; FacesCtrlLOVBinding.ListOfValuesModelImpl listOfValuesModel = null; ViewCriteria viewCriteria = null; Object submittedValue = null; ViewCriteriaRow viewCriteriaRow = null; RowSet rowSet = null; Row listRow = null; Row baseViewObjectRow = null; if (!launchPopupEvent.isLaunchPopup()) { return; } submittedValue = launchPopupEvent.getSubmittedValue(); if (submittedValue == null) { return; } BindingContext bindingContext = BindingContext.getCurrent(); BindingContainer bindingContainter = bindingContext.getCurrentBindingsEntry(); RichInputListOfValues inputListOfValues = (RichInputListOfValues)launchPopupEvent.getComponent(); if(inputListOfValues != null) { // below code gets the value expression for the current column i.e in our case #{bindings.DepartmentId.inputValue} valueExpression = inputListOfValues.getValueExpression(inputListOfValues.VALUE_KEY.getName()).toString(); if (valueExpression != null) { // if the column is in the af table then the value will be #{row.bindings.DepartmentId.inputValue} so we are replacing row. valueExpression = StringUtils.replace(valueExpression, "row.", ""); currentColumnName = valueExpression.substring(valueExpression.indexOf(".")+1, valueExpression.lastIndexOf(".")); if (currentColumnName != null) { ctrlListBinding = (JUCtrlListBinding)bindingContainter.getControlBinding(currentColumnName); if (ctrlListBinding != null) { baseViewObject = ctrlListBinding.getIteratorBinding().getViewObject(); if (baseViewObject != null) { baseViewObjectRow = baseViewObject.getCurrentRow(); lovAttributeDef = baseViewObject.findAttributeDef(currentColumnName); if (lovAttributeDef != null) { listBindingDef = lovAttributeDef.getListBindingDef(); if (listBindingDef != null) { listAttributeNames = listBindingDef.getListAttrNames(); if (listAttributeNames != null && listAttributeNames.length > 0) { listOfValuesModel = (FacesCtrlLOVBinding.ListOfValuesModelImpl)inputListOfValues.getModel(); if (listOfValuesModel != null) { viewCriteria = listOfValuesModel.getCriteria(); if (viewCriteria !=null) { viewCriteriaRow = (ViewCriteriaRow)viewCriteria.getRowAtRangeIndex(0); if (viewCriteriaRow != null) { lovlistAttributeDef = viewCriteriaRow.getStructureDef().findAttributeDef(listAttributeNames[0]); if (lovAttributeDef != null) { if (lovAttributeDef.getSQLType() == OracleTypes.NUMBER) { viewCriteriaRow.setAttribute(listAttributeNames[0], submittedValue); viewCriteriaRow.getCriteriaItem(listAttributeNames[0]).setOperator(JboCompOper.OPER_EQ); }else if (lovAttributeDef.getSQLType() == OracleTypes.VARCHAR) { viewCriteriaRow.setAttribute(listAttributeNames[0], submittedValue+"%"); viewCriteriaRow.getCriteriaItem(listAttributeNames[0]).setOperator(JboCompOper.OPER_LIKE); } listOfValuesModel.applyCriteria(); listOfValuesModel.performQuery(listOfValuesModel.getQueryDescriptor()); if (ctrlListBinding.getListIterBinding().getRowSetIterator() != null && ctrlListBinding.getListIterBinding().getRowSetIterator().getRowCount() > 0) { rowSet = ctrlListBinding.getListIterBinding().getRowSetIterator().getRowSet(); listRow = rowSet.getRowAtRangeIndex(0); if (listRow != null && listRow.getAttribute(listAttributeNames[0]).equals(submittedValue)) { if (baseViewObjectRow != null) { baseViewObjectRow.setAttribute(currentColumnName, submittedValue); } RowKeySetImpl rowKeySet = new RowKeySetImpl(); List list = new ArrayList(); list.add(listRow.getKey()); launchPopupEvent.setLaunchPopup(false); launchPopupEvent.queue(); inputListOfValues.queueEvent(new ReturnPopupEvent(inputListOfValues,rowKeySet)); AdfFacesContext.getCurrentInstance().addPartialTarget(inputListOfValues); } } } } } } } } } } } } } } }
No comments:
Post a Comment