Monday, May 13, 2013

ADF - Programatically Applying and Creating View Criteria

CASE 1: I have already created a view criteria in EmployeeVO, and I want to call it programmatically.
    public void searchEmployee(Number employeeId) {
        ViewObjectImpl vo = getEmployeesView1();
        ViewCriteria vc = vo.getViewCriteria("findEmployeeVC");
        vo.applyViewCriteria(vc);
        vo.setNamedWhereClauseParam("pEmployeeId", employeeId);
        vo.executeQuery();
    }

CASE 2: I want to create a view criteria dynamically and execute it programmatically.
    public void searchByEmployeeIdEmail(Number employeeId, String email) {
        ViewObjectImpl vo = getEmployeesView2();
        ViewCriteria vc = vo.createViewCriteria();
        ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
        
        vcRow.setAttribute("EmployeeId", employeeId);
        vc.addRow(vcRow);
        vcRow.setAttribute("Email", email);
        vc.addRow(vcRow);
        
        vo.applyViewCriteria(vc);
        vo.executeQuery();
    }

7 comments:

  1. Dear sir,
    This is Guru Tata,
    I have small doubt on this concept,
    You are passing the attributes and executing the query, if i need to capture the result from this query what are the possible approaches could you suggest me to write a program..
    Thanking you in anticipation..
    let me know through my mail id
    My Mail id is:tataguravaiah116@gmail.com

    ReplyDelete
  2. Download the sample application from File Cabinet: VCExample.rar

    ReplyDelete
  3. Hi, I wrote some custom code and exposed them to the VO client, The method appears in the data control. Now, I can use the method when i drag and drop to the page as a button, and I can successfully apply view criteria .

    Now I have problem applying the same in Customisation mode, when I drag drop the button to page, no binding window appears and I am not able to pass the parameter to the Java code. Please guide.

    ReplyDelete
  4. Hi, I wrote some custom code and exposed them to the VO client, The method appears in the data control. Now, I can use the method when i drag and drop to the page as a button, and I can successfully apply view criteria .

    Now I have problem applying the same in Customisation mode, when I drag drop the button to page, no binding window appears and I am not able to pass the parameter to the Java code. Please guide.

    ReplyDelete
  5. Dear Sir I wrote this method on the AppModuleImpl

    public BigDecimal GetItemPriceFc(BigDecimal It){
    BigDecimal price=new BigDecimal(0);
    ViewObject vo = getItemsView1();
    ViewCriteria vc = vo.createViewCriteria();
    ViewCriteriaRow vcr1 = vc.createViewCriteriaRow();
    vcr1.setAttribute("Itid",It);
    vc.add(vcr1);
    vo.applyViewCriteria(vc);
    vo.executeQuery();
    if(vo.hasNext()){
    Row row = vo.next();
    price = (BigDecimal)row.getAttribute("Price");}
    return price;
    }

    and I tried to use it in my vo (InvoiceDetViewRowImpl)

    public BigDecimal getU_price() {
    BigDecimal price = new BigDecimal(0);
    AppModuleImpl am = new AppModuleImpl();
    price = am.GetItemPriceFc(getItid());
    // return (BigDecimal) getAttributeInternal(U_PRICE);
    return price;
    }

    just catch the result and a sign to my column

    its give error like this
    java.lang.NullPointerException
    and when I try to trace this code
    its stop here at this code I wrote message after its not come
    ViewCriteria vc = vo.createViewCriteria();

    also when I used this method with exposed it and drop it on my page its working fine

    your prompt action highly appreciated

    ReplyDelete