DunDmy
DunDmy

Reputation: 275

Removing trailing spaces in <af:query>

I am wondering if the JDeveloper comes with a preset configuration setting that lets you remove any trailing spaces from the given string. After, I add an additional space to my string inside af:query search criteria, the search displays 0 results. Since I am using the View Criteria to define my where clause, is there any way I could trim the search criteria to display my query in the JDeveloper? Thank you in advance!

Upvotes: 2

Views: 488

Answers (2)

YLG
YLG

Reputation: 885

There is no preset configuration in the Jdeveloper. But if you want to trim String selected from search query component. So you can override queryListner attribute in af:query tag.

As example,

 <af:query id="qryId2" headerText="Search" disclosed="true"
                          value="#{bindings.CreationDtVCriteriaQuery.queryDescriptor}"
                          model="#{bindings.CreationDtVCriteriaQuery.queryModel}"
                          queryListener="#{pageFlowScope.mainHandler.ProcessQuery}"
                          queryOperationListener="#{bindings.CreationDtVCriteriaQuery.processQueryOperation}"
                          resultComponentId="::pc5:resId1"
                          binding="#{pageFlowScope.mainHandler.tableQuery}"
                          displayMode="compact" saveQueryMode="hidden"
                          modeChangeVisible="false"
                          inlineStyle="width:500px"/>

Here in above example you can see the overridden queryListener method.

Now if view criteria contains 2 fields in search components as

  Enquiry Name ( This is display name, In VO it is as EnqName) (Input text field)
  Enquiry Id   ( This is display name, In VO it is as EnqId) (Input text field)

Now in the backing bean,

  public void ProcessQuery(QueryEvent queryEvent) {

    ConjunctionCriterion conCrit = qd.getConjunctionCriterion();
    //access the list of search fields
    List<Criterion> criterionList = conCrit.getCriterionList();
    for (Criterion criterion : criterionList) {
        AttributeDescriptor attrDescriptor =
            ((AttributeCriterion)criterion).getAttribute();

     if (attrDescriptor.getName().equalsIgnoreCase("EnqName")) {
        //To check which field is accessed from above both 
        //as in order, EnqName comes first and then EnqId , This condition returns true
         System.out.println("Retrived value is " ((AttributeCriterion)criterion).getValues().get(0));
         trim(((AttributeCriterion)criterion).getValues().get(0)); //trim it.. and use it
      }

    if (attrDescriptor.getName().equalsIgnoreCase("EnqId")) {
    //To check which field is accessed from above both 
      System.out.println("Retrived value is " ((AttributeCriterion)criterion).getValues().get(0));
      trim(((AttributeCriterion)criterion).getValues().get(0)); //trim it.. and use it
  }
    }
  }

The trim function is already available for java. So you can store retrieved value in String and trim it. Hope this may help.

Upvotes: 1

DunDmy
DunDmy

Reputation: 275

Unfortunately, there is no preset configuration in the JDeveloper that would let you trim a string inside your query component. In order to solve this problem, you will have to create a custom method that will retrieve all search fields that have search parameters entered, trim them, set them back and use them as your AttrivetureCriterion.

Upvotes: 1

Related Questions