Thursday, January 12, 2012

Applying two or more than two view criteria programmatically on view object at a time

Hi ,

It is very common requirement to apply view criteria programmatically on view object.But also there is possibility that you want to apply two or more view criteria  at a same time.

For that purpose there is one overloaded method present into business layer.And method is



 applyViewCriteria(ViewCriteria,boolean);

Using this overloaded method you can apply your second view criteria while first view criteria has already applied.The first aurgument is type criteria object and second one type is boolean where you can pass true or false value.If it is true it will apply view criteria on already applied view criteria result.

Example:
In my Employees VO i have created three view criteria.And i want to applied them programmatically.
Therefore i have created EmployeesViewImpl class and written following method

    public void applyALLViewCriteria(String firstName, Number salary,
                                     String jobId) {
        ViewCriteria vcFN = getViewCriteria("FirstNameVC");
        ViewCriteria vcSA = getViewCriteria("SalaryVC");
        ViewCriteria vcJ = getViewCriteria("JobVC");
        vcFN.resetCriteria();
        vcSA.resetCriteria();
        vcJ.resetCriteria();
        setfirstName(firstName);
        applyViewCriteria(vcFN);
        setsalaryB(salary);
        applyViewCriteria(vcSA, true);
        setjobID(jobId);
        applyViewCriteria(vcJ, true);
        executeQuery();
    }



Thanks
Prateek