Thursday, February 11, 2016

Reset Sort and Filter Criteria

Issue: Clearing the values entered in QBE (Query by example) and Sort fields of a table


If the user enters a value in the QBE or filter and perform some kind of sort on fields above the header of the attribute columns the values are not cleared even after reset.  

It keeps the values and applies the Sort and filter criteria even after reset and search.


Solution:




The utility method below would clear out both the filter and Sort criteria applied by the user on click of reset.

The utility method takes the results table and the Iterator as the input and clears the sort and filter criteria applied by the user.

To call the method you have to write the custom query operation listener and check if the operation name is RESET.

public static void clearFilterCriteria(RichTable targetTable, String       iterator) {
targetTable.queueEvent(new SortEvent(targetTable,new                           ArrayList<SortCriterion>()));
SortCriteria[] sc = new SortCriteria[0];
        //Clears the Sort Criteria        ADFUtils.findIterator(iterator).applySortCriteria(sc);
FilterableQueryDescriptor queryDescriptor =            (FilterableQueryDescriptor)targetTable.getFilterModel();  
if (queryDescriptor != null && queryDescriptor.getFilterCriteria() != null) {           // Clears the Filter Criteria            queryDescriptor.getFilterCriteria().clear();}
}
}


Cascading LOV : Default Value

Issue: In Cascading LOV's if one of the child LOV's had single value then it should be selected by default as soon as the user selects the value in parent LOV


Solution: 

The trick is to access the ViewAccessor of the LOV, check the estimated row count and if it is 1 then get the value and set it to the attribute of the View object.

Creating RowImpl for the view object and in the getter of the attribute add the following code


    /**     * Gets the attribute value for the calculated attribute LocationId.
     * @return the LocationId
     */
    public Number getLocationId() {
        return this.getLocationsLOV1().getRowCount() == 1
                 ? ((DBSequence)this.getLocationsLOV1().first().getAttribute("LocationId")).getSequenceNumber()
                 : (Number)getAttributeInternal(LOCATIONID);
    }