Sie sind auf Seite 1von 8

9/24/2016

ADFPractice:ADFBC.ProgrammaticallypopulatedVOexample.

ADFPractice
23Jan2011

AboutMe

Eugene
Fedorenko
Utrecht,
Netherlands

ADFBC.ProgrammaticallypopulatedVOexample.
Introduction
Viewobjectswithrowspopulatedprogrammaticallycanbeveryusefultodisplaydatafromalternativedata
sourceslikePL/SQLprocedure'soutparameters,RefCursors,XMLfiles,...
InthispostIwillshowhowtobuildviewobjectanddisplayinformationaboutPL/SQLprocedure's
parameters.HowtogetthisinformationyoucanseeinthepreviouspostADFBC.PL/SQLprocedure
params.

Iamamaster
principalR&D
architectat
eProseedNL
focusingon
ADF.
Viewmycompleteprofile

TocreateVOwithrowspopulatedprogrammaticallyyouneedtoselect"Rowspopulated
programmatically,notbasedonquery"optioninthe"CreateViewObject"wizard:

PopularPosts

ADFBC.
Programmaticall
ypopulatedVO
example.
Introduction
Viewobjects
withrowspopulated
programmaticallycanbevery
usefultodisplaydatafrom
alternativedatasourceslike
PL/SQL...

OnthenextstepofthewizardyouhavetodefineattributesofyourVO:

Understanding
theJSF
Immediate
Attribute
Thereisvery
commonmythamongADFand
JSFdevelopersthatusing
Immediateattributewillavoid
unnecessaryvalidationinany
case.Itiso...
Howtoapply
ViewCriteria
programmaticall
y
Sometimesit
couldbehandy
toapplyviewcriteria
dynamicallyatruntime.Let's
sayIhaveasimpleVO
EmployeesViewrepresenting
da...

AfterfinishingthewizardJDeveloperisgeneratingsourceViewObjectImplcodewithsomemethods
supposedtobeoverriddenlikethis:

packagecom.cs.blog.sproc.model
importjava.sql.ResultSet
importoracle.jbo.server.ViewObjectImpl
importoracle.jbo.server.ViewRowImpl
importoracle.jbo.server.ViewRowSetImpl
//
//FilegeneratedbyOracleADFBusinessComponentsDesignTime.
//TueJan0418:47:17EET2011
//Customcodemaybeaddedtothisclass.

http://adfpracticefedor.blogspot.com.eg/2011/01/adfbcprogrammaticallypopulatedvo.html

Updatemodelin
the
ValueChangeLis
tener
Afterreadingofthe
UnderstandingtheJSF
ImmediateAttributepost,my
friendaskedmewhetherthere
isanysensetousethe
Immediateatt...
Managedbean
scopesforpage
fragmentsin
ADFTaskFlow
Introduction
Whenwework
withADFTaskFlowsandneed
toimplementsomeflowspecific
businesslogicorstoresome
informationconnectedw...
WorkingwithPL/SQL
proceduresinADFBCModel
Ibelievethisisverycommon
usecasewhenweneedto

1/8

9/24/2016

ADFPractice:ADFBC.ProgrammaticallypopulatedVOexample.
//Warning:Donotmodifymethodsignaturesofgeneratedmethods.
//
publicclassVStoredProcParams1ImpextendsViewObjectImpl{
/**
*Thisisthedefaultconstructor(donotremove).
*/
publicVStoredProcParams1Imp(){
}
/**
*executeQueryForCollectionoverriddenforcustomjavadatasourcesupport.
*/
protectedvoidexecuteQueryForCollection(Objectqc,Object[]params,
intnoUserParams){
super.executeQueryForCollection(qc,params,noUserParams)
}
/**
*hasNextForCollectionoverriddenforcustomjavadatasourcesupport.
*/
protectedbooleanhasNextForCollection(Objectqc){
booleanbRet=super.hasNextForCollection(qc)
returnbRet
}
/**
*createRowFromResultSetoverriddenforcustomjavadatasourcesupport.
*/
protectedViewRowImplcreateRowFromResultSet(Objectqc,
ResultSetresultSet){
ViewRowImplvalue=super.createRowFromResultSet(qc,resultSet)
returnvalue
}
/**
*getQueryHitCountoverriddenforcustomjavadatasourcesupport.
*/
publiclonggetQueryHitCount(ViewRowSetImplviewRowSet){
longvalue=super.getQueryHitCount(viewRowSet)
returnvalue
}
}

invokesomePL/SQLprocedure
inourJavacodeinADFBC
model.Thestandard
approach...
Understanding
ViewAccessors
IntroductionIn
anADF
applicationa
viewaccessoris
consideredasanapproachto
accessaviewobjectfrom
anotherviewobjectorentity...
Workingwithaf:iteratorand
HashMapvalues
InthispostI'mgoingtoshowa
coupleofexamplesofusing
af:iteratorcomponenttorender
HashMapvalues.Let'ssayin
mymanaged...
ManagedBean
Scopesfor
Component
Binding
Everybody
knowsthatJSF
UIcomponentscanbeboundto
somemanagedbeanproperty
usingcomponent'sbinding
attribute.Likethis:<...
Understanding
IteratorBinding
RefreshAttribute
InthispostIam
goingtofocuson
theRefresh
attributeofanIteratorBinding
thatwedefineinthepage
definitionfile.&l...

Labels

ADF(8)
ADFBC(22)
ADFTrian(3)
af:iterator(1)
af:query(1)

Actually,youhavetoimplementalittlebitmoremethods:

AMPooling(2)
Array(2)

/**
/**
*Overriddenframeworkmethod.
*
*WipeoutalltracesofabuiltinqueryforthisVO
*/
protectedvoidcreate(){
getViewDef().setQuery(null)
getViewDef().setSelectClause(null)
setQuery(null)
}

Associations(1)
AutoPPR(1)
autosuggestion(1)
backingBean(3)
BC(1)
Bindings(3)
Book(1)
Camera(1)
Cancel(1)
clientevents(1)
clientComponent(1)
Collection(2)

/**
*executeQueryForCollectionoverriddenforcustomjavadatasourcesupport.
*/
protectedvoidexecuteQueryForCollection(Objectqc,Object[]params,
intnoUserParams){
storeNewResultSet(qc,retrieveParamsResultSet(qc,params))
super.executeQueryForCollection(qc,params,noUserParams)
}

Componentbinding(1)
CSS(1)
Custom(2)
customproperties(1)
DataControl(1)
Declarativecomponent(3)
DeclarativeSQL(2)
DeepDive(2)
Dynamic(7)

privateResultSetretrieveParamsResultSet(Objectqc,Object[]params){
Dynamicform(2)
ResultSetrs=
Dynamictable(1)
StoredProcParams.getStoredProcParams(getDBTransaction(),(String)getParamValue(PACKAGE_NAME,
Entitycache(2)
params),
(String)getParamValue(PROCEDURE_NAME,
ExceptionHandler(1)
params))
Finalizer(1)
returnrs
FlexDeploy(2)
}

http://adfpracticefedor.blogspot.com.eg/2011/01/adfbcprogrammaticallypopulatedvo.html

2/8

9/24/2016

ADFPractice:ADFBC.ProgrammaticallypopulatedVOexample.
getCappedQueryHitCount(1)
Groovy(3)

privateObjectgetParamValue(StringvarName,Object[]params){
if(getBindingStyle()==SQLBuilder.BINDING_STYLE_ORACLE_NAME){
if(params!=null){
for(Objectparam:params){
Object[]nameValue=(Object[])param
Stringname=(String)nameValue[0]
if(name.equals(varName)){
returnnameValue[1]
}
}
}
}
thrownewJboException("Nobindvariablenamed'"+varName+"'")
}

HashMap(1)
Immediate(3)
Inheritance(1)
inputDate(1)
JavaScript(2)
JboValidatorInterface(1)
JDevR2(1)
JRebel(1)
Lifecycle(1)
ListView(1)
LOV(11)
MAF(1)
methodIterator(1)
nested(1)

/**
*Storeanewresultsetinthequerycollectionprivateuserdatacontext
*/
privatevoidstoreNewResultSet(Objectqc,ResultSetrs){
ResultSetexistingRs=(ResultSet)getUserDataForCollection(qc)
//Ifthisquerycollectionisgettingreused,closeoutanypreviousrowset
if(existingRs!=null){
try{
existingRs.close()
}catch(SQLExceptione){
thrownewJboException(e)
}
}
setUserDataForCollection(qc,rs)
hasNextForCollection(qc)//Primethepumpwiththefirstrow.
}

Objecttypes(1)
OOW2012(2)
OOW2013(1)
pagetemplates(1)
Passivation/Activation(1)
PL/SQL(2)
popup(3)
POST(1)
PPR(1)
Presentation(1)
programmatically(4)
Resourcebundles(1)
Rowset(2)
Savepoints(1)
selectBooleanCheckBox(1)
Separator(1)

/**
*hasNextForCollectionoverriddenforcustomjavadatasourcesupport.
*/
protectedbooleanhasNextForCollection(Objectqc){
ResultSetrs=(ResultSet)getUserDataForCollection(qc)
booleannextOne=false
if(rs!=null){
try{
nextOne=rs.next()
/*
*Whenwereattheendoftheresultset,markthequerycollection
*as"FetchComplete".
*/
if(!nextOne){
setFetchCompleteForCollection(qc,true)
/*
*Closetheresultset,we'redonewithit
*/
rs.close()
}
}catch(SQLExceptions){
thrownewJboException(s)
}
}
returnnextOne
}
/**
*createRowFromResultSetoverriddenforcustomjavadatasourcesupport.
*/
protectedViewRowImplcreateRowFromResultSet(Objectqc,
ResultSetresultSet){
resultSet=(ResultSet)getUserDataForCollection(qc)

Skin(1)
TaskFlow(9)
Transaction(1)
transient(2)
UIcategories(1)
URL(1)
Validation(5)
ViewAccessors(3)
ViewLinks(1)
Viewable(1)
ViewCriteria(8)
VO(15)
WebLogic(1)
WebSocket(1)

Searchthisblog
Loading...

BlogArchive

2016(9)
2015(16)
2014(21)
2013(24)
2012(20)
2011(24)
December(2)
November(1)
September(1)
August(2)

/*
*Createanewrowtopopulate
*/
ViewRowImplr=createNewRowForCollection(qc)

http://adfpracticefedor.blogspot.com.eg/2011/01/adfbcprogrammaticallypopulatedvo.html

July(2)
June(2)
May(4)
April(2)

3/8

9/24/2016

ADFPractice:ADFBC.ProgrammaticallypopulatedVOexample.
if(resultSet!=null){
try{
/*
*PopulatenewrowbyattributeslotnumberforcurrentrowinResultSet
*/
populateAttributeForRow(r,0,
resultSet.getString("COLUMN_NAME"))
populateAttributeForRow(r,1,
resultSet.getString("DATA_TYPE"))
populateAttributeForRow(r,2,
resultSet.getString("TYPE_NAME"))
}catch(SQLExceptions){
thrownewJboException(s)
}
}
returnr
}
protectedvoidreleaseUserDataForCollection(Objectqc,Objectrs){
ResultSetuserDataRS=(ResultSet)getUserDataForCollection(qc)
if(userDataRS!=null){
try{
userDataRS.close()
}catch(SQLExceptions){
}
}
super.releaseUserDataForCollection(qc,rs)
}

March(2)
February(3)
January(3)
UsingInheritanceinView
ControllerLayer
ADFBC.Programmatically
populatedVOexample.
ADFBC.PL/SQLprocedure
params.

Blogs

WebLogicCommunity
CreatingaMobileOptimized
RESTAPIUsingMobileCloud
ServicePart4bySteven
Davelaar
7hoursago

JDev&ADFGoodies
SummaryofDay4attheOracle
OpenWorld2016
1dayago

AndrejusBaranovskis
SlidesAvailableEndtoEnd
Cloud:OracleJavaCloud,
OracleMobileCloudService,
OracleMAF,andOracleJET
[CON2388]
4daysago

DecompilingADFBinaries

/**
*getQueryHitCountoverriddenforcustomjavadatasourcesupport.
*/
publiclonggetQueryHitCount(ViewRowSetImplviewRowSet){
return0
}

Therearetwomostimportantmethodstofocusyourattention:retrieveParamsResultSetand
createRowFromResultSet.
MethodretrieveParamsResultSetactuallyretrievesdatafromyouralternativedatasource.Inmycasethisis
somestaticmethodsupposedtoreturninformationaboutPL/SQLprocedure'sparamsrepresentedby
ResultSetwiththreeattributes(COLUMN_NAME,DATA_TYPEandTYPE_NAME).

MethodcreateRowFromResultSetcreatesnewrowandpopulatesattributesofyourviewobjectbyvaluesof
COLUMN_NAME,DATA_TYPEandTYPE_NAME.
InadditionIdefinedtwoparameters(bindvariables)formyVOpackageNameandprocName(PL/SQL
packageandprocedurenamestobedescribed).

'RESTfulJavaWebServices
SecondEdition'ispublished!
1yearago

TheGroundBlogbyDuncan
Mills
MethodReferencesand
<af:declaritiveComponent>
1yearago

ADFCodeCornerOracle
JDeveloperOTNHarvest
MAF2.1NewtaskFlow
PageFlowScopeDefault:push
new
1yearago

TotalPageviews

Followers
(53)

Iimplementedandpublished(viaclientinterface)somemethodtosetupvaluesfortheseparameters:

publicvoidinitParamValues(StringpackageName,StringprocName){
setpackageName(packageName)
setprocName(procName)
executeQuery()
}

FollowbyEmail

Emailaddress...

Submit

Visitors

IcreatedjspxpageanddroppedthismethodasaparametersformandVOasatable.Asaresultofour

http://adfpracticefedor.blogspot.com.eg/2011/01/adfbcprogrammaticallypopulatedvo.html

4/8

9/24/2016

ADFPractice:ADFBC.ProgrammaticallypopulatedVOexample.
workIgotsomethinglikethis(sorryfordesign):

DownloadsampleapplicationforthispostAppOraStoredProc.zip.ItrequiresconnectiontostandardHR
schemeinOracledatabase.
PostedbyEugeneFedorenkoat09:46

+1 Recommend this on Google

LiveTrafficFeed
AvisitorfromAlexandria,Al
Iskandariyahviewed"ADF
Practice:ADFBC.
ProgrammaticallypopulatedVO
AvisitorfromAlexandria,Al
example."1secsago
Iskandariyahviewed"ADF
Practice:ADFBC.
ProgrammaticallypopulatedVO
AvisitorfromUtrechtviewed
example."45minsago
"ADFPractice"51minsago
AvisitorfromBangalore,
Karnatakaviewed"ADF
Practice:ADFBC.
ProgrammaticallypopulatedVO
AvisitorfromChennai,Tamil
example."1hr30minsago
Naduviewed"ADFPractice"2
hrs10minsago
AvisitorfromKualaLumpur
viewed"ADFPractice:
Handlingkeymodifiersfor
clientevents"2hrs12minsago
AvisitorfromUnitedKingdom
viewed"ADFPractice:
DisplayingADFTaskFlow
StackwithBreadCrumbs"2hrs
AvisitorfromBangalore,
24minsago
Karnatakaviewed"ADF

Labels:ADF,programmatically,VO

16comments:
Amar 19August2011at04:45
Hello,
I'mreferringtothefollowinglinktopopulateVOprogramattically.
http://adfpracticefedor.blogspot.com/2011/01/adfbcprogrammaticallypopulatedvo.html
WhenrunindebugIseethatresultsetisgettingreturnedappropriatelyandiscallingthemethodsoverriden
asperthelink.However,Nodataisdisplayedinthetable.

Practice:BuildingCustomLOV
withsearchContentFacet"2hrs
AvisitorfromBangalore,
32minsago
Karnatakaviewed"ADF
Practice:UnderstandingIterator
BindingRefreshAttribute"2hrs
AvisitorfromCairo,Al
54minsago
Qahirahviewed"ADFPractice:
Validatingdateswith
af:validateDateTimeRange
RealtimeviewGetFeedjit

I'musingJDeveloperStudioEditionVersion11.1.1.4.0
Anysuggestionsplease.
SubscribeTo

Regards,
Amar

Posts

Reply

EugeneFedorenko

Comments

22August2011at02:19

HelloAmar,
Probablythecursorinyourresultsetobjectispositionedattheend.DebughasNextForCollectionmethodto
checkthis.

VisitorsMap

Reply

Dilkhush 2November2011at22:09
Hello,
I'mreferringtothefollowinglinktopopulateVOprogramattically.
http://adfpracticefedor.blogspot.com/2011/01/adfbcprogrammaticallypopulatedvo.html
I'musingJDeveloperStudioEditionVersion11.1.1.4.0
DatabaseSQlServer
MyissueishowtosetBindVariablevaluesfrommanagedbeanbecauseIcan'tuseInputTextonmypage
tosetthosevaluesasyoudid.ThecodeisgivenbelowhowImsettingthatvalue
OperationBindingopBinding=
CommonUtil.getOperationBinding("#{bindings}",
"initParamValues")
opBinding.getParamsMap().put("custID",customerID.getValue().toString())
opBinding.getParamsMap().put("accountType",
{bindings.ADAccountType.attributeValue}")).toString())
opBinding.getParamsMap().put("productID",
{bindings.DMAProductId.attributeValue}")).toString())
opBinding.getParamsMap().put("entityID",homeEntityID)
opBinding.getParamsMap().put("schemeCode",linkText)

(CommonUtil.evaluateEL("#
(CommonUtil.evaluateEL("#

http://adfpracticefedor.blogspot.com.eg/2011/01/adfbcprogrammaticallypopulatedvo.html

5/8

9/24/2016

ADFPractice:ADFBC.ProgrammaticallypopulatedVOexample.
opBinding.execute()

Anysuggestionsplease.

Regards,
Dilkhush
Reply

EugeneFedorenko

12December2011at06:06

Hi!So,what'swrongwiththiscode?Theconceptiscorrect.
Icannotsaywhetheritworksornot.Idon'tknowwhatiscustomerID,homeEntityID,linkText.
AndyoucanmapaccountTypeandproductIDparametersinpageDef:
"NamedDataNDName="accountType"NDType="java.lang.String"
NDValue="${bindings.ADAccountType}"
Reply

RajdeepChaudhary 9July2012at10:32
Doyouhaveanyexposure"HowtohandletheviewcriteriaforprogrammaticVO?"
Thanks,
Rajdeep
Reply

EugeneFedorenko

22September2012at08:27

HiRajdeep!
Since the VO is being populated programmatically, you can't let the framework perform filtering in the
database,becauseyoudon'thaveaSQLquery.So,youhavetospecify"Inmemory"queryexecutionmode
fortheViewCriteriasoftheprogrammaticallypopulatedVO.
Reply

ValonSejdini 12December2012at15:43
HiEugene,
Thanksforthegreatshare.
Isitpossibletoenablepaginationsupport(i.e.rangepaging)inaprogrammaticviewobject?
Itriedtoimplementsimilartohere:
http://docs.oracle.com/cd/E14004_01/books/SSDev/SSDev_CustomizingModel17.html#wp1012199
Ican'tgetittowork.
ThanksALot.
Valon
Reply
Replies
EugeneFedorenko

5February2013at09:57

Yes,itspossible.Thistechniqueisabitmorecomplicatedthanprovidedinthispost.IthinkIm
going to blog about it. But the question is in your datasource used in the PP VO. Does your
datasourcesupportpagination?Canitprovideapage,Imeanaportionofrowsthatyouneed?
Forexampleasetofrowsfromnumber10uptonumber25.Onlyinthiscaseyouwillgainreal
benefitsfromthepaginationfeature.

Anonymous 12March2013at22:01
HiEugene,
Didyoublogonthistopic?Iwouldliketoenablepaginationsupporttoo.
Thanks
Math
Reply

Anonymous 17January2013at10:55

http://adfpracticefedor.blogspot.com.eg/2011/01/adfbcprogrammaticallypopulatedvo.html

6/8

9/24/2016

ADFPractice:ADFBC.ProgrammaticallypopulatedVOexample.
Isitpossible(andistherevalue)toprogrammaticallypopulateanEntityObjectsothatmultipleViewObject
instancescanshapethedataasneededfromasingleversionofthePL/SQLresults?
Reply
Replies
EugeneFedorenko

5February2013at10:05

Yes,itis.AndIevenhaveseensomeexamplesofprogrammaticallypopulatedentityobjects.
ButforthisusecaseIwouldpreferalittlebitdifferentapproach.Iwouldusemultiplerowsetsof
theVO.Havealookatthetechniquesdescribedhere:
http://adfpracticefedor.blogspot.com/2012/01/viewobjectworkingwithmultiple.html
http://adfpracticefedor.blogspot.com/2012/05/multipleiteratorbindingsforoneview.html
Reply

ViralPatel 22April2014at07:25
HiEugene,
Thanksfortheshare.
I have implemented the same scenario by overriding executeQueryForCollection(Object qc, Object[]
params, int noUserParams) in VOImpl and called stored Procedure and mapped the data by overriding
ViewRowImplcreateRowFromResultSet(Objectqc,ResultSetresultSet).
IhaveexposedtheVOasTableanditsworkingfine.
NowIhavearequirementtosortthedataintable.
PleasehelpandsuggesthowdoIachieveit???
Viral
Reply

EugeneFedorenko

22April2014at07:28

HiViral,
Areyougoingtosortthedatayourselfprogrammaticallyoryouneedtoallowuserstoperformsorting?
Reply
Replies
ViralPatel 29April2014at05:38
HiEugene,
Sorryforlatereply....
Iwantedtoperformsortingbasedonuserinputs(iefromaf:tablesortingbuttons)
ifyouhaveanyideathenpleasehelp.
Viral

Reply

EugeneFedorenko

29April2014at06:11

HiViral!
You have to create your custom data control as it is described here http://adfpractice
fedor.blogspot.com/2013/04/adfbcworkingwithcustomdatacontrol.html
IntheoverriddenapplySortCriteriamethoddothefollowing:
protectedvoidapplySortCriteria(DCIteratorBindingiter,SortCriteria[]sortBy){
if(sortBy!=null){
ViewObjectvo=iter.getViewObject()
JboEnvUtil.applyVOSortCriteria(vo,sortBy,true/*Transient*/)
}
}
Reply
Replies
ViralPatel 29April2014at06:42
Thanksforreply...
Iwilltrythisout:)

http://adfpracticefedor.blogspot.com.eg/2011/01/adfbcprogrammaticallypopulatedvo.html

7/8

9/24/2016

ADFPractice:ADFBC.ProgrammaticallypopulatedVOexample.
Reply

Addcomment

PostComment

Enteryourcomment...

Commentas:

Publish

Unknown(Google)

Signout

Notifyme

Preview

NewerPost

Home

OlderPost

Subscribeto:PostComments(Atom)

Copyright20102011EugeneFedorenko.Simpletemplate.PoweredbyBlogger.

http://adfpracticefedor.blogspot.com.eg/2011/01/adfbcprogrammaticallypopulatedvo.html

8/8

Das könnte Ihnen auch gefallen