- Follow the post "How to create an Oracle ADF Fusion Web Application?", to create an application, change the application name and suffix.
- Now start creating view object.
Right click on the model project and select the view
object from gallery.
- Now give the name of view object, Lets say "ProgrameticViewObject" and select the Data source as Programmatic.
click next.
- Now star creating the transient attributes for view object by clicking on new button.
and click next.
- Now for each attribute specify the constraints.and click next.
- Now generate a view object class for customization to insert a row Programmatic and click next.
- If want to work with this view object on view layer then create view object instance on Application module impl xml file.click next.
- Following structure of view object, and click finish.
- Now to insert row on view object, open ProgrameticViewObjImpl.java class
- Now to work with view object class , it is important to know the view object lifecycle, for this refer to the post "LifeCycle of View Object".
a. first of all create a getter setter of all
attributes mentioned on view Object.
from gallery.
select java class and click ok.
b. Specify the name of class and package and click ok. Let say
"Employee".
c. Following class is created.
d. Now create a getter and setter of viewobject attributes in Employee.java
class.
- Now open Programmatic view object impl class file.
Following steps to be perform :-
a. view object first call the viewObjectImpl
class method executeQueryforCollection() here create a list of data to insert on view object.
b. Then next method hasNextForCollection(Object qc) method which
check the row on query collection, if it returns true then move to another
method else exit.
By default their is no row in query collection so we add the blank row on 0
index.
c. Then it moves to createRowFromResultSet(Object
qc, ResultSet resultSet) method , which is responsible to insert row on
view object.
Following Code :-
import java.sql.ResultSet;
import java.util.ArrayList;
import oracle.jbo.Row;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;
import vo.model.pojo.Employee;
// ---------------------------------------------------------------------
// --- File generated by Oracle ADF Business Components Design Time.
// --- Wed Mar 01 10:54:29 IST 2017
// --- Custom code may be added to this class.
// --- Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class ProgrameticViewObjectImpl extends ViewObjectImpl {
ArrayList<Employee> list=new ArrayList<Employee>();
/**
* This is the default constructor (do not remove).
*/
public ProgrameticViewObjectImpl() {
}
/**
* executeQueryForCollection - overridden for custom java data source support.
*/
@Override
protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams) {
//start inserting the value from pojo class in arraylist
list.add(new Employee(1,"palash",24));
list.add(new Employee(2,"rajat",25));
list.add(new Employee(3,"sakshi",23));
setRowPosition(qc,0);
super.executeQueryForCollection(qc, params, noUserParams);
}
/**
* hasNextForCollection - overridden for custom java data source support.
*/
@Override
protected boolean hasNextForCollection(Object qc) {
boolean bRet = ((Integer)getUserDataForCollection(qc))< list.size();
return bRet;
}
/**
* createRowFromResultSet - overridden for custom java data source support.
*/
@Override
protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet resultSet) {
ViewRowImpl value = createNewRowForCollection(qc);
int fetchSize=(Integer)getUserDataForCollection(qc);
Employee c= list.get(fetchSize);
value.setAttribute("EmployeeId", c.getEmpId());
value.setAttribute("EmployeeName", c.getEmpName());
value.setAttribute("Age", c.getAge());
setRowPosition(qc, fetchSize+1);
return value;
}
/**
* getQueryHitCount - overridden for custom java data source support.
*/
@Override
public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
long value = super.getQueryHitCount(viewRowSet);
return value;
}
/**
* getCappedQueryHitCount - overridden for custom java data source support.
*/
@Override
public long getCappedQueryHitCount(ViewRowSetImpl viewRowSet, Row[] masterRows, long oldCap, long cap) {
long value = super.getCappedQueryHitCount(viewRowSet, masterRows, oldCap, cap);
return value;
}
private void setRowPosition(Object rowset, int position) {
if (position == list.size()) {
setFetchCompleteForCollection(rowset, true);
}
setUserDataForCollection(rowset, new Integer(index));
}
- Lets test the view object.
0 comments:
Post a Comment