You are on page 1of 5

8/27/2016

UseViewLinkAccessortocallaggregatefunctions,setattributevalue,setbindvariablesvalue(OracleADF)AshishAwasthi'sBlog(Jdev/ADF)

UseViewLinkAccessortocallaggregatefunctions,setattributevalue,set
bindvariablesvalue(OracleADF)
HelloAll
Thispostisaboutvarioususageofviewlinkaccessor,whenwecreate
viewLinkbetweentwoviewObjects,destinationaccessoriscreatedby
defaultinmasterviewObject,thereischeckboxtocreatesourceaccessor
alsoatsametime
Wecanusethisviewlinkaccessorforcalculatingattribute'ssum,setting
valueofattributesetc

hereDepartmentsismasterviewObjectandEmployeesisit'sdetail,aftercreatingviewLinkyoucanseeinviewObjectxmlsourcethere
accessorispresent
InDepartmentsViewObject

<ViewLinkAccessor
Name="Employees"
ViewLink="sample.model.view.link.DeptTOEmpVL"
Type="oracle.jbo.RowIterator"
IsUpdateable="false"/>
http://www.awasthiashish.com/2014/08/useviewlinkaccessortocall.html

1/5

8/27/2016

UseViewLinkAccessortocallaggregatefunctions,setattributevalue,setbindvariablesvalue(OracleADF)AshishAwasthi'sBlog(Jdev/ADF)

InEmployeesViewObject

<ViewLinkAccessor
Name="Departments"
ViewLink="sample.model.view.link.DeptTOEmpVL"
Type="oracle.jbo.Row"
Reversed="true"
IsUpdateable="false"/>
Sowhatistheuseoftheseviewlinkaccessors?
MasteraccessorindetailviewObjectreturnscurrentRowofmasterviewObject,whenyougenerateRowImplclassfordetail
viewObject,italsohasamethodforthisaccessor

/**
*Getstheassociated<code>Row</code>usingmasterdetaillinkDepartments.
*/
publicRowgetDepartments(){
return(Row)getAttributeInternal(DEPARTMENTS);
}
/**
*SetsthemasterdetaillinkDepartmentsbetweenthisobjectand<code>value</code>.
*/
publicvoidsetDepartments(Rowvalue){
setAttributeInternal(DEPARTMENTS,value);
}
DetailaccessorinmasterviewObjectreturnsarowsetofallrowofdetailsviewObjectthatarecurrentlyreferencedbymasterrecord
/**
*Getstheassociated<code>RowIterator</code>usingmasterdetaillinkEmployees.
*/
publicRowIteratorgetEmployees(){
return(RowIterator)getAttributeInternal(EMPLOYEES);
}
NowseewhatwecandowithviewLinkAccessor

1.GetmasterattributevalueindetailviewObject
supposeihavetogetaattribute'svaluefromMasterviewObject(Departments)inaattributeofdetailviewObject(Employee)
inthisexampleiamgettingmanagerIdfromDepartmentsViewObjectsoforthisjustwriteinexpressionofEmployee'sManagerIdfield
viewLinkAccesorName.AttributeName

http://www.awasthiashish.com/2014/08/useviewlinkaccessortocall.html

2/5

8/27/2016

UseViewLinkAccessortocallaggregatefunctions,setattributevalue,setbindvariablesvalue(OracleADF)AshishAwasthi'sBlog(Jdev/ADF)

nowrunBC4JtesterandcheckcreatenewrecordinEmployeeandseemanagerIdfromDepartmentsisautopopulated

oncreatingnewrecord

2.CallaggregatefunctiontocalculatesumofanattributeofdetailviewObject
supposenowihavetocalculatetotalsalaryofaDepartment(sumofEmployeessalaryofthatdepartment)
forthispurposejustcallsumfunctiontocalculatesumofallrowsofdetailRowSet
takeatransientattributeinDepartmentsViewObjectandwriteinit'sexpression
viewLinkAccesorName.sum("AttributeName")

http://www.awasthiashish.com/2014/08/useviewlinkaccessortocall.html

3/5

8/27/2016

UseViewLinkAccessortocallaggregatefunctions,setattributevalue,setbindvariablesvalue(OracleADF)AshishAwasthi'sBlog(Jdev/ADF)

RunApplicationModuleandsee

3.SetbindvariablevalueaspermasterviewObject'sattribute(passvaluefrommasterviewObject)
Thisistrickypartaswecannotsetbindvariablevaluethroughexpressionasitdoesn'trecognizeviewlinkaccessorname.
createdaviewCriteriaandbindvariableformanagerIdinEmployeeviewObject

appliedthiscriteriatoEmployeesviewObjectinstanceinApplicationModule(JustShuttlecriteriatoselectedside)

http://www.awasthiashish.com/2014/08/useviewlinkaccessortocall.html

4/5

8/27/2016

UseViewLinkAccessortocallaggregatefunctions,setattributevalue,setbindvariablesvalue(OracleADF)AshishAwasthi'sBlog(Jdev/ADF)

nowtosetbindvariable'svaluewehavetooverrideprepareRowSetForQuerymethodinEmployeesVOImplclass

thismethodgetsthevalueofmanagerIdfromcurrentRowofmasterViewObject(Departments)andsetsinbindvariableofEmployees
viewObject

@Override
publicvoidprepareRowSetForQuery(ViewRowSetImplviewRowSetImpl){
RowSetIterator[]masterRows=viewRowSetImpl.getMasterRowSetIterators();
if(masterRows!=null&&masterRows.length>0&&masterRows[0].getCurrentRow()!=null&&
masterRows[0].getCurrentRow().getAttribute("ManagerId")!=null){
IntegermanagerId=(Integer)masterRows[0].getCurrentRow().getAttribute("ManagerId");
viewRowSetImpl.ensureVariableManager().setVariableValue("BindManagerId",managerId);
System.out.println("ManagerIDinbindVar"+managerId);
}
super.prepareRowSetForQuery(viewRowSetImpl);
}
nowrunAMandcheckit

HappyLearning

http://www.awasthiashish.com/2014/08/useviewlinkaccessortocall.html

5/5

You might also like