Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:12:57 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

April 2004
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Mar   May

Get Firefox!

Friday, April 16, 2004

A user wrote in to ask, "How could I turn every user-entered query criteria on string attributes into an uppercased, wildcard query without the user having to remember to enter upper-case or the wildcard character in their criteria?"

The place to override in your ViewObjectImpl subclass to solve this problem is the getViewCriteriaClause() method. You can iterate the (possibly multiple!) view criteria rows that have been specified by the user, and adjust the values of the specified query-by-example criteria before returning the super.getViewCriteriaClause() value. We would just need to uppercase the values of criteria supplied for String-valued attributes and then tack on a percent sign at the end of their value to make them wildcard queries.

For example, if you only wanted to do this for a certain "Ename" attribute, you could write a helper method in your EmpViewImpl.java class like this:

  private String adjustEnameViewCriteriaToUppercaseWildcards() {
    ViewCriteria vc = getViewCriteria();
    if (vc != null) {
      ViewCriteriaRow vcr = (ViewCriteriaRow)vc.first();
      while (vcr != null) {
        String criteria = (String)vcr.getAttribute("Ename");
        if (criteria != null) {
          vcr.setAttribute("Ename","%"+criteria.toUpperCase()+"%");
        }
        vcr = (ViewCriteriaRow)vc.next();
      }
    }
    return super.getViewCriteriaClause();
  }

And then call your helper method in an overridden getViewCriteriaClause() method like this:

  public String getViewCriteriaClause() {
    adjustEnameViewCriteriaToUppercaseWildcards();
    return super.getViewCriteriaClause();
  }

To do something more general -- say, for all the string-valued attributes -- you could use a more generalized helper method like this:

  private void adjustStringViewCriteriaToUppercaseWildcards() {
    ViewCriteria vc = getViewCriteria();
    if (vc != null) {
      ViewCriteriaRow vcr = (ViewCriteriaRow)vc.first();
      AttributeDef[] attrs = vc.getViewObject().getAttributeDefs();
      int attrCount = attrs.length;
      while (vcr != null) {
        for (int z = 0; z < attrCount; z++) {
          if (attrs[z].getSQLType() == Types.VARCHAR ) {
            String criteria = (String)vcr.getAttribute(z);
            if (criteria != null) {
              vcr.setAttribute(z,criteria.toUpperCase()+"%");
            }           
          }
        }
        vcr = (ViewCriteriaRow)vc.next();
      }
    }   
  }

Then just have your overridden getViewCriteriaClause() method invoke this helper method instead.

To test out your work, you can use the Business Components Tester tool that's built-into JDeveloper (right-mouse Test... on your application module in the navigator). When viewing your view object, their is a "Specify View Criteria" toolbar button that allows you to enter one or more rows of View Criteria query-by-example criteria. The (OR>>) button in "Business Component View Criteria" dialog, allows you to add multiple view criteria pages. Each tabbed page in this dialog represents one view criteria row in the view criteria collection for the view object you're working with.

I tried applying the more generalized version of the above tip on an EmpView and then used this tester dialog to enter search criteria of "sm" for Ename and "cl" for Job, and when I clicked (Find), it found the "SMITH" employee who is a "CLERK".

 


10:01:27 AM    



© Copyright 2008 Steve Muench.