This discussion is archived
6 Replies Latest reply: Nov 20, 2012 6:07 AM by kdario RSS

Changing View Criteria on runtime

918256 Newbie
Currently Being Moderated
Hi

Is it possible to change the view criteria query in java?
something like this:

in ViewObjectImpl

getViewCriteria("filterByAllDates").setWhereClause(getViewCriteria("filterByAllDates").getWhereclause + " AND ABC = 1");

is this possible?

thanks
  • 1. Re: Changing View Criteria on runtime
    918256 Newbie
    Currently Being Moderated
    Or changint it anywhere else, because creating view criterias can only use the options given in JDeveloper, Bu iI need to add my own
  • 2. Re: Changing View Criteria on runtime
    Shay Shmeltzer Employee ACE
    Currently Being Moderated
    The ViewCriteria has a full API that you can use from a service method on your VO for example.
    http://docs.oracle.com/cd/E35521_01/apirefs.111230/e17483/toc.htm
    Also the VO has a method called setWhereClause that you can use in a similar way.
    https://blogs.oracle.com/shay/entry/am_service_method_-simpledem
  • 3. Re: Changing View Criteria on runtime
    AlejandroProfet Journeyer
    Currently Being Moderated
    Hi,

    You can set an existing bind variable (which is set as parameter of existing view criteria item):
    ViewCriteria vc = vo.getViewCriteria("filterByAllDates");
    vo.setNamedWhereClauseParam("abcBindVar", value);
    vo.applyViewCriteria(vc);
    vo.executeQuery();
    or you can create a new view criteria row programmatically:
    VariableValueManager vvm = vo.ensureVariableManager();
    ViewCriteria vc = vo.createViewCriteria();
    ViewCriteriaRow vcr = vc.createViewCriteriaRow();
    ViewCriteriaItem vci = vcr.ensureCriteriaItem("AbcAttributeInVO"); // name of attribute in VO
    vci.setOperator(JboCompOper.OPER_EQ);
    vci.setRequired(ViewCriteriaItem.VCITEM_REQUIRED);
    VariableImpl var = (VariableImpl)vvm.addVariable("abcBindVar"); // name of bind variable
    var.setJavaType(String.class);
    var.setMandatory(true);
    var.setUpdateableFlag(Variable.UPDATEABLE);
    var.setVariableKind(Variable.VAR_KIND_VIEW_CRITERIA_PARAM);
    var.setProperty(AttributeHints.ATTRIBUTE_DISPLAY_HINT, AttributeHints.ATTRIBUTE_DISPLAY_HINT_HIDE);
    vci.setValue(0, ":abcBindVar");
    vci.setIsBindVarValue(0, true);
    vvm.setVariableValue(var, "1"); // value to set
    vc.insertRow(vcr);
    vo.applyViewCriteria(vc);
    vo.executeQuery();
    AP
  • 4. Re: Changing View Criteria on runtime
    kdario Expert
    Currently Being Moderated
    Yes, you can do this, but it's not clear what exactly you are trying to do:

    - if you need to programmatically add new attribute then you can use something like:
    ViewCriteria vc = vo.getViewCriteria("filterByAllDates");
    ViewCriteriaRow vcr = vc.createViewCriteriaRow();
    .
    .
    - if you need to add custom operator, then use this as starting point:
    http://adfnbpel.wordpress.com/2012/07/05/adf-view-criteria-with-in-clause/
    http://tompeez.wordpress.com/2011/08/21/extending-viewcriteria-to-use-sql-contains-4/

    - if you need to override whole dynamic where clause, then you can implement custom CriteriaAdapter:
    http://radio-weblogs.com/0118231/stories/2003/07/11/implementingAViewCriteriaAdapterToCustomizeQueryByExampleFunctionality.html

    Dario
  • 5. Re: Changing View Criteria on runtime
    918256 Newbie
    Currently Being Moderated
    Thanks for the response, the first one I already knew,

    but my problem is this:

    My view Criteria is of type 'OR' and
    I need to add this line:

    OR contains(content, '% 'BINDVARIABLE' %' , 1) > 0;

    because I want to serch inside a BLOB field on a view criteria
    is this possible? because the list of operators doesn't have the 'contains' like this on a Blob field
  • 6. Re: Changing View Criteria on runtime
    kdario Expert
    Currently Being Moderated
    So, did you read http://tompeez.wordpress.com/2011/08/21/extending-viewcriteria-to-use-sql-contains-4/ ?

    Dario

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points