Tag Archives: view criteria

TO_CHAR to TO_DATE problem addressed


Recently found this issue on an internal forum and found the solution given by Jobinesh.. Thought I could share the info here

Problem description:

“I’m trying to apply a view criteria programmatic way here. When the bind variable for “StartDate” (which is a VO attribute) uses just a “=”. then at runtime the VC gets appended to the query using a TO_DATE for the bind var, which is as expected. However, when the bind variable for “StartDate” uses just a “>=” / “<“>” . then at runtime the VC gets appended to the query using a TO_CHAR for the bind var, which is not that we require. Is there any way to get a TO_DATE for this kind of comparison as well?”

Please take a look at the following sample method :-

public Row getSampleHeaderVORecord(Date activeDate) {
 ViewObjectImpl SampleHeaderVO = getSampleHeader1();
 ViewCriteria viewCriteria = SampleHeaderVO.createViewCriteria() ;
 ViewCriteriaRow vcr1 = viewCriteria.createViewCriteriaRow() ;
 vcr1.setAttribute("StartDate", ">="+(activeDate.));
 viewCriteria.add(vcr1);
 SampleHeaderVO.applyViewCriteria(viewCriteria);
 SampleHeaderVO.executeQuery();
 return SampleHeaderVO.next();
 }

Do let me know.

Sample query that appears at runtime :-

SELECT *WHERE ( ( (TO_CHAR( ForecastHeaderEO.START_DATE, 'yyyy-mm-dd') > '0007-04-02' ) ) )

The TO_CHAR in the last line is what I’m referring to. Is there any way to get a TO_DATE there?

Solution:


ViewObjectImpl SampleHeaderVO = getSampleHeader1();
 ViewCriteria viewCriteria = SampleHeaderVO.createViewCriteria() ;
 ViewCriteriaRow vcr1 = viewCriteria.createViewCriteriaRow() ;
 ViewCriteriaItem vci = vcr1.ensureCriteriaItem("StartDate");
 vci.setOperator(JboCompOper.OPER_ON_OR_AFTER);
 vci.setValue(activeDate);
viewCriteria.add(vcr1);
 SampleHeaderVO.applyViewCriteria(viewCriteria);
 SampleHeaderVO.executeQuery();

How to hide the viewcriteria from the af:query panel


If you want to hide the view criteria, then here is the easy way
The code is written in the setter of the af:query binding

public void setQuery_binding(RichQuery query_binding) {

 this.query_binding = query_binding;

 DCBindingContainer bindings = (DCBindingContainer)this.getBindings();
 DCIteratorBinding iter =
 bindings.findIteratorBinding("<TableIterator>");

 ViewObjectImpl voimpl = (ViewObjectImpl)iter.getViewObject();
 ViewCriteria vc =  voimpl.getViewCriteriaManager().getViewCriteria("");
 vc.setProperty(ViewCriteriaHints.CRITERIA_SHOW_IN_LIST, ViewCriteriaHints.CRITERIA_HINT_FALSE);

 }
  • getting the handle to the iterator
  • getting handle to the ViewCriteriaManager, and then getting handle to the specific view criteria that we wanted to hide
  • modifying the ViewCriteriaHints.CRITERIA_SHOW_IN_LIST property to false

note: helper method – getBindings()

 private BindingContainer getBindings() {
 if (this.bindings == null) {
 FacesContext fc = FacesContext.getCurrentInstance();
 this.bindings =
 (BindingContainer)fc.getApplication().evaluateExpressionGet(fc,
 "#{bindings}",
 BindingContainer.class);
 }
 return this.bindings;
 }