Follow by Email

Monday, 15 April 2013

Creating and Executing ViewCriteria Programmatically

Sometimes you need dynamic ViewCriteria that you can handle at runtime ,
here is the solution ,you can create and apply ViewCriteria Programmatically-



Sample UseCase-
  • Suppose you have Department VO
  • You want to filter this VO for DepartmentId 10
  • Do this using this code snippet

  • /**Get ViewObject*/
    ViewObject vo = getAm().getDepartments1();
    /**Create ViewCriteria on ViewObject*/
    ViewCriteria vc = vo.createViewCriteria();
    /**Create ViewCriteriaRow for that Criteria*/
    ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
    /**Set the values for ViewCriteriaRow*/
    vcRow.setAttribute("DepartmentId", 10);
    /**Add row to ViewCriteria*/
    vc.addRow(vcRow);
    /**Apply Criteria on ViewObject*/
    vo.applyViewCriteria(vc);
    /**Execute ViewObject*/
    vo.executeQuery();

    public pcAMImpl getAm() {
    pcAMImpl am = (pcAMImpl)resolvElDC("pcAMDataControl");
    return am;
    }

2 comments :

  1. Hi,

    Not Understand below method. Can you please explain or share some screenshot..

    public pcAMImpl getAm() {
    pcAMImpl am = (pcAMImpl)resolvElDC("pcAMDataControl");
    return am;
    }

    ReplyDelete
    Replies
    1. Dinesh

      This is the way to get ApplicationModule in managed bean and pcAMImpl is the name of application module impl class
      but don't use this way of calling method instead see How to invoke model layer methods from managed bean (Best Practice to write business logic in ADF)

      Ashish

      Delete