Please disable your adblock and script blockers to view this page

Search this blog

Thursday 4 May 2017

Implement contains/endswith behavior in model based autoSuggest Lov (Input list and combo box)


Hello All

Hope Everyone knows about list of values and autoSuggest beahvior of ADF Framework,
For those who are new to framework can look at this post
ADF Basics : Implementing auto suggest behavior in ADF Faces lov (list of values)



By default autoSuggest search beahvior is "STARTSWITH" means when user types any string in input part of lov then framework shows all suggestion that starts with input string
Now requirement is to change default behavior of autoSuggest search so for this I have googled it and found two wonderful post of Andrejus Baranovskis (Thanks)

Suppressing ADF LOV Like Operator Filtering
Suppressing ADF LOV Like Operator Filtering V2

These both post talk about another problem with lovs that opens search popup for suggested values and Andrejus uses a solution that overrides lov view criteria operator to not to show any suggested values .
I have used same method to override lov auto suggestion view criteria operator to implement contains behavior

Here I have applied Departments Lov on Employee viewObject's Department Id attribute and default autoSuggest behavior is like this


In the above blogposts it is mentioned that framework executes a view criteria named  __lov__filterlist__vcr___ to retrieve suggested values so to override this viewCirteria create ViewObjectImpl class of Departments ViewObject (LOV ViewObject) and override applyViewCriteria method and used same method to override lov operator 
See this code here I am using CONTAINS operator in place of STARTSWITH

    @Override
    public void applyViewCriteria(ViewCriteria viewCriteria, boolean b) {
        super.applyViewCriteria(supressLikeOperatorForLov(viewCriteria), b);
    }

    private ViewCriteria supressLikeOperatorForLov(ViewCriteria vc) {
        //Check for VC name, If cirtera is executed for suggested values
        if (vc != null && vc.getName().toLowerCase().contains("__lov__filterlist__vcr___")) {
            //Get current row of ViewCriteria (Current operation)
            ViewCriteriaRow row = (ViewCriteriaRow) vc.getCurrentRow();
            if (row != null) {
                //Get criterai items
                ArrayList criteriaItems = (ArrayList) row.getCriteriaItems();
                for (int i = 0; i < criteriaItems.size(); i++) {
                    ViewCriteriaItem criteriaItem = (ViewCriteriaItem) criteriaItems.get(i);
                    if (criteriaItem != null) {
                        if ("STARTSWITH".equals(criteriaItem.getOperator())) {
                            //Change STARTSWITH operator to CONTAINS
                            criteriaItem.setOperator("CONTAINS");
                        }
                    }
                }
            }
        }
        return vc;
    }

And see how this works, For same input it shows all that suggested values that contains 'S'


In same way we can implement other operators too , just replace CONTAINS with ENDSWITH and see the result


Cheers :) Happy Learning

8 comments :

  1. Excellent post, very helpful.

    ReplyDelete
  2. Thanks for this post sir , How can we hide input lov search dialog as I don't want user to open this

    ReplyDelete
  3. Wow its good, u r always awesome every problem can be resolved by ur post, I wish u live long and keep posting like dis thanks..

    ReplyDelete
  4. Thanks very much , ur enemies may die by seeing it again and again.

    ReplyDelete
  5. Being anonymous means the person doesn't have courage for his own shit, I wish for your well being
    We love you, you're doing a great job

    ReplyDelete
  6. Thank you friends for your love and support :)

    ReplyDelete