Posts Tagged ‘ViewObjectImpl’

There are very few references about this so I thought to post it here.

To get the query you have to override the executeQueryForCollection() in your ViewObjectImpl. Before calling super(), you can get/print out the result of getQuery() method.

protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams) {
getQueryParameters();
q = getQuery();
System.out.println(“SQL = ” + q);
if (params != null) {
for (int i = 0; i < params.length; i++) {
Class cls = params[i].getClass();
System.out.println(“Class is ” + cls.getName());
System.out.println(“Query param ” + i + ” ” + String.valueOf(params[i]));
}
}
super.executeQueryForCollection(qc, params, noUserParams);
}

There are several different methods on getting ViewObjects in ADF programmatically. It is possible to create a method within the Application Module Impl or your view object Impl class and then call that method through your managed bean or you can even call it directly within your managed bean but the first method is suitable.

1- Within the application module

ViewObjectImpl vo = getYourViewObject();
ViewCriteria vc = vo.getViewCriteria(“MyCriteria”);
vo.applyViewCriteria(vc);
vo.setNamedWhereClauseParam(“some_param”, anyParam);
vo.executeQuery();
Row row = vo.getCurrentRow();

2- Within your View Object

ViewCriteria vc = getViewCriteria(“MyCriteria”);
applyViewCriteria(vc);
setNamedWhereClauseParam(“some_param”, anyParam);
executeQuery();

3- Within your Managed Bean

AppModuleImpl am = new AppModuleImpl();
ViewObjectImpl vo = am.getYourViewObject();
ViewCriteria vc = getViewCriteria(“MyCriteria”);
vo.applyViewCriteria(vc);
vo.setNamedWhereClauseParam(“some_param”, anyParam);
vo.executeQuery();