Вы находитесь на странице: 1из 92

6/8/2015

CreatingaMasterDetailForm

CreatingaMasterDetailForm
Purpose
InthislessonyoulearnhowtocreateabasicmasterdetailFormwithOracleFormsBuilder10g.

Topics
Thislessondiscussesthefollowing:
Overview
Prerequisites
Step1SettingUptheDevelopmentEnvironment
Step2BuildingaDataBlock
Step3AddingNonBaseTableItemstoaDataBlock
Step4BuildingaDetailBlock
Step5CreatingaNewCanvas
Step6CreatingaNewWindow
Step7BuildingaControlBlock
Step8ControllingNavigation
Step9ModifyingtheLayout
Step10AddingFunctionalitywithCode
Summary

Timetocomplete
Thislessontakesapproximately75minutestocomplete.

ViewingScreenshots
Moveyourmouseoverthisicontoshowallscreenshots.Youcanalsomoveyourmouseovereachindividualicon
toseeonlythescreenshotassociatedwithit.

Overview
ThelessonguidesyouthroughmanyofthetasksthatyoumustperformwhenusingOracleFormsBuildertocreateamaster
detailform.YouusetheDataBlockWizardtoquicklygeneratethemasteranddetailblocks,thenyouaddacontrolblock
(onewithnobasetableitems)totheform.Youaddsomenonbasetableitemstothedatablocks,andusePL/SQLtriggersto
addfunctionalitytotheform.
BacktoTopicList

Scenario
Youaredesigningahumanresourceapplication.OneofthemainformsinthisapplicationisintendedtoenableHRclerksto
maintaindepartmentandemployeeinformation.Youhavedecidedtoimplementthisasamasterdetailformthatdisplays
onedepartmentwithallemployeesinthedepartment.

Prerequisites
BacktoTopicList
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

1/92

6/8/2015

CreatingaMasterDetailForm

Inorderforthislessontoworksuccessfully,youneedtohaveperformedthefollowing:
1.

InstallOracleDeveloperSuite10g.

2.

Installthesampleschemastouseinthislesson.SeeInstallingtheSampleSchemasandEstablishinga
DatabaseConnection.
YoudonotneedtocreateadatabaseconnectioninJDeveloperjusthavetheHRschemaavailablesothat
youcanconnecttoitinForms.Ensurethatthetnsnames.orafileintheNetwork\Admindirectoryofthe
DeveloperSuiteinstallationcontainsanentrytoconnecttothedatabasewheretheHRschemaisavailable.

Step1SettingUptheDevelopmentEnvironment
BacktoTopicList
OracleDeveloperSuite10gincludesastandaloneversionofOracle10gContainersforJ2EE(OC4J),whichyoucanuseas
aWeblistenerandaservletcontainertotestFormsapplications.Togetreadytobuildandtestaform,performthefollowing
steps:
1.

FromtheWindowsStartmenu,selectPrograms|OracleDeveloperSuiteiDS10g|FormsDeveloper|Start
OC4JInstance.

2.

Youcanminimizethecommandpromptwindowwhenthewindowdisplaysthemessage"OracleApplication
ServerContainersforJ2EE10g(9.0.4.0.0)initialized".
Moveyourmouseoverthisicontoseetheimage
Note:DonotclosetheOC4JInstancewindow.WhenyouwanttostopOC4J,choosePrograms|Oracle
DeveloperSuiteiDS10g|FormsDeveloper|StopOC4JInstancefromtheWindowsStartmenu.

3.

FromtheWindowsStartmenu,selectPrograms|OracleDeveloperSuiteiDS10g|FormsDeveloper|Forms
Builder.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

2/92

6/8/2015

4.

CreatingaMasterDetailForm

WhenFormsBuilderstarts,anemptyformisautomaticallycreatednamedModule1.SelecttheModule1name,
thenclickitagaintochangethenameoftheform.TypeinthenameHRandpressEnter.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

3/92

6/8/2015

CreatingaMasterDetailForm

5.

ClickSave

.Bydefault,Formssavesfilesinthe\bindirectoryofyourDeveloperSuiteinstallation.You

maywanttosaveitinadifferentdirectoryifdesired,youcancreateanewdirectorycalledMyFormsinwhichto
savetheapplication.

6.

ConnecttothedatabaseastheHRuserbyclickingConnect

andthenenteringtheuserid,password,and

connectstringforthedatabasethatcontainstheHRorHR8schema(seePrerequisites).

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

4/92

6/8/2015

CreatingaMasterDetailForm

Step2BuildingaDataBlock
BacktoTopicList
Transactionalapplicationsneedtobeabletoinsert,update,anddeleterecordsfromthedatabase.Thedatablockisthe
mechanismthatmakesthispossibleinaFormsapplication.Adatablockisalogicalgroupingofitemsthatusuallyare
associatedwithasingledatabasetable,view,orsetofstoredprocedures,althoughthedatablockmaycontainnonbase
tableitemsalso.
FormsBuilderincludesaDataBlockWizardtomakeitpossibletoeasilycreateadatablockandaLayoutWizardtolayout
theitemsontheform'scanvas.TousetheDataBlockWizardandtheLayoutWizardtocreateadatablockanddefineits
layout,performthefollowingsteps:
1.

SelecttheDataBlocksnodeintheObjectNavigator,thenclickCreate

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

5/92

6/8/2015

CreatingaMasterDetailForm

2.

IntheNewDataBlockdialog,ensurethatUsetheDataBlockWizardisselected,thenclickOK.

3.

IftheWelcometotheDataBlockWizardpagedisplays,clickNext>.
Youcanbaseadatablockonadatabasetableorview,oronasetofstoredproceduresinwhichyoucan
definecomplicatedquery,insert,update,anddeletelogic.Forthisapplicationyoubasetheblockonatable,so
ensurethatTableorViewisselected,thenclickNext>.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

6/92

6/8/2015

CreatingaMasterDetailForm

4.

IntheTableorviewfield,typedepartmentsforthetablename,thenclickRefresh.Clicktherightdouble
arrowbutton
tomoveallavailablecolumnstotheDatabaseItemstobeincludedintheblock,thenclick
Next>.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

7/92

6/8/2015

5.

CreatingaMasterDetailForm

Acceptthedefaultnamefortheblock,whichisthesameasthetablename,andclickNext>.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

8/92

6/8/2015

6.

CreatingaMasterDetailForm

OnthefinalpageoftheDataBlockWizard,clickFinishtocreatethedatablockandinvoketheLayoutWizard.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

9/92

6/8/2015

7.

CreatingaMasterDetailForm

IftheWelcometotheLayoutWizardpagedisplays,clickNext>.
AcceptthedefaultsandclickNext>tolayouttheitemsonanewcontentcanvas.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

10/92

6/8/2015

CreatingaMasterDetailForm

Note:Acontentcanvasisonethatfillstheentirewindow.Youcandisplayonlyonecontentcanvasatatime
withinawindow.Othercanvastypesaretoolbar,stacked,andtabcanvases,whichtypicallyresideinaportion
ofawindowwhilethecontentcanvasremainsatleastpartiallyvisible.

8.

Youdecidetodisplayonlythedepartmentidanddepartmentname,becausethelocationidandmanagerid
arejustnumbersthatarenotmeaningfultotheuser.
ControlclickDEPARTMENT_IDandDEPARTMENT_NAMEintheAvailableItemslist,thenclicktheright
singlearrowbutton
tomovethemtotheDisplayedItemslist.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

11/92

6/8/2015

CreatingaMasterDetailForm

ClickNext>.

9.

ClickNext>toacceptthedefaultitemprompt,width,andheightforbothitems.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

12/92

6/8/2015

CreatingaMasterDetailForm

10. ClickNext>toaccepttheFormlayout.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

13/92

6/8/2015

CreatingaMasterDetailForm

11. FortheFrameTitleenterDepartment,thenclickNext>.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

14/92

6/8/2015

CreatingaMasterDetailForm

12. OnthefinalpageoftheLayoutWizard,clickFinishtocreatethecanvasandopenitintheLayoutEditor.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

15/92

6/8/2015

CreatingaMasterDetailForm

13. IntheLayoutEditor,youcanperformanycosmeticchangesthatyouwanttothelayout.
First,toensurethatchangestothelayoutframearepreserved,doubleclicktheframe(thelinethatsurrounds
theitems)toinvokeitsPropertyPalette.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

16/92

6/8/2015

CreatingaMasterDetailForm

Note:YoucanleavethePropertyPaletteopenitdisplaysthepropertiesforwhateverobjectiscurrently
selected.IfyoushouldclosethePropertyPalette,youcanreopenitbyselectingTools|PropertyPalettefrom
theFormsBuildermenu.Alternatively,doubleclickingmostFormsobjectsopensthePropertyPaletteforthat
object.

14. InthePropertyPalettefortheFrame,changethepropertyUpdateLayoutfromAutomaticallytoManually.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

17/92

6/8/2015

CreatingaMasterDetailForm

15. Enlargetheframebyclickingthehandleinitslowerrightcorneranddraggingitdownwardandtotheright.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

18/92

6/8/2015

CreatingaMasterDetailForm

onthetoolbarattheleftoftheLayoutEditor.Withthemouse,clickand
16. ClicktheRoundedRectangletool
dragarectanglearoundthedepartmentidandthedepartmentname.

ontheLayoutEditortoolbarandpicka
17. WiththerectangleselectedintheLayoutEditor,clickFillColor
colorfortherectangle.(Youmayneedtoclickthearrow
atthebottomofthetoolbartoscrolldownto
theFillColorbuttoniftheLayoutEditorwindowistoosmalltodisplayallthetools.)

18. ClickSave

tosaveyourform.

Step3AddingNonBaseTableItemstoaDataBlock
BacktoTopicList
TheDepartmentsblockisbasedontheDepartmentsdatabasetable,andsofaralltheitemsintheblockrepresentcolumns
inthattable.However,thereisoftenaneedtoincludeitemsintheblockthatarenotinthebasetablefortheblock.One
commonuseofnonbasetableitemsistodisplayinformationfromrelatedtables.
TheDepartmentsblockcontainstwoitemsthatdonotappearonthecanvas:Manager_IdandLocation_Id.Youcansee
theseitemsintheObjectNavigator.Insteadofdisplayingthesenumberswhicharenotmeaningfultotheuser,youwantto
displaythemanager'snameandthelocationcity,state/province,andcountry.
Toaddnonbasetableitemstodisplayrelatedinformation,performthefollowingsteps:

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

19/92

6/8/2015

1.

CreatingaMasterDetailForm

IntheLayoutEditor,clicktheDisplayItemtool

.Clickapointonthecanvasjustbelowthedepartment

nametocreateaDisplayItem.ThenclicktheDisplayItemtoolagain,andclickapointonthecanvasjustbelow
thedisplayitemthatyoujustcreated.

Note:ADisplayItemissimilartoaTextItem(usedforDepartment_IdandDepartment_Name),exceptthatit
doesnotacceptuserinput.Ifyouwantuserstobeabletochangethesevalues,youshoulduseaTextItem.

2.

ControlclickeachoftheDisplayItemstoselectthemboth.Alternatively,youcandragthemousearoundboth
itemstoselectthem,beingcarefultoincludeonlythosetwoitems.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

20/92

6/8/2015

CreatingaMasterDetailForm

3.

ThePropertyPaletteshouldnowdisplaythepropertiesforbothdisplayitems.Ifbothdisplayitemshavethe
samevalueforaproperty,thevalueisdisplayed.Ifthetwodisplayitemshavedifferentvaluesforaproperty,
asterisksaredisplayedforthatproperty.
Selectingbothdisplayitemsenablesyoutochangepropertiestoidenticalvaluesforbothitems.
ChangethefollowingpropertiesinthePropertyPaletteforbothdisplayitems:
Property

Value

MaximumLength

65

DatabaseItem

No

Height

14

PromptAttachmentOffset

Hint:Ifyouhavetroublelocatingaparticularproperty,typeitsnameintheFindboxatthetoprightofthe
PropertyPalette.Assoonasyouhavetypedenoughletterstouniquelyidentifytheproperty,FormsBuilder
highlightsthatpropertyinthePropertyPalette.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

21/92

6/8/2015

4.

CreatingaMasterDetailForm

Changethefollowingpropertiesforonlythefirstdisplayitembyselectingitsingly(clickanareaoutsidethetwo
displayitemstodeselectthem,thenclickthefirstdisplayitem):
Property

Value

Name

LOCATION

Prompt

Location

Changethefollowingpropertiesfortheseconddisplayitemonly:
Property

Value

Name

MANAGER

Prompt

Manager

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

22/92

6/8/2015

5.

CreatingaMasterDetailForm

MovethesecondDisplayItemupslightlysoitisjustunderthefirst.Aneasywaytomoveanitemashort
distanceistoselectitandthenusethearrowkeystonudgetheitemtoitsdesiredposition.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

23/92

6/8/2015

CreatingaMasterDetailForm

6.

Toensurethatallitemsareproperlyaligned,selectallitems(donotincludethepromptsinthisselection)and
clickAlignLeft
ontheLayoutEditortoolbar.

7.

IntheLayoutEditor,clickintotheitempromptsDepartmentNameandDepartmentId.Deletetheword
"Department"frombothprompts.Alternatively,youcanchangetheitempromptsinthePropertyPalettefor
eachitem.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

24/92

6/8/2015

8.

CreatingaMasterDetailForm

ClickSave

tosavetheform,thenclickRunForm

totestit(besurethatyouhavestartedOC4Jsee

Step1).
Whentheformstartsrunning,clickExecuteQuery
PreviousRecord

todisplaydataintheform.ClickNextRecord

and

tonavigatebetweenrecords.

Note:AtthispointtheLocationandManageritemsarenotpopulatedyouwritecodetopopulatetheseitemsin
alaterstep.

9.

ClickExitForm

toexittheapplication,thenclosethebrowserwindow.

CAUTION:AlwaysexittheapplicationbyclickingtheExitFormbuttonpriortoclosingthebrowser.Failure
todothismaycausetheRunformprocesstohangifthishappens,youneedtoopenTaskManagerand
endtheifweb90.exeprocess.

Step4BuildingaDetailBlock
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

25/92

6/8/2015

CreatingaMasterDetailForm

BacktoTopicList
FormsDevelopergivesyoutheabilitytoquicklydefineadditionaldatablocks.TheDataBlockWizardoffersyoutheoptionof
definingrelationsbetweenthenewblocksandanyexistingblocksintheform.
NowthatyouhaveaDepartmentsblock,youwouldliketobeabletoadditionallydisplayalltheemployeesineach
department.TocreateadetailblockbasedontheEmployeestable,performthefollowingsteps:
1.

SelectDepartmentsintheObjectNavigator,thenclickCreate

.Thisensuresthatthenewblock

immediatelyfollowsDepartmentsintheObjectNavigatortree.Thesequenceoftheblocksdeterminesdefault
navigationandalsothesequenceofcommitprocessing.

Note:Ifyouhappentocreateanobjectinthewrongorder,youcandragitsicontothedesiredpositioninthe
ObjectNavigator.Forexample,ifthesequenceoftheblocksisEmployees,thenDepartments,youcandragthe
EmployeesblockicontoapositionafterDepartmentsundertheDataBlocksnode.

2.

IntheNewDataBlockdialog,ensurethatUsetheDataBlockWizardisselected,thenclickOK.

3.

IftheWelcometotheDataBlockWizardpagedisplays,clickNext>.
Youarebasingtheblockonatable,soensurethatTableorViewisselected,thenclickNext>.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

26/92

6/8/2015

4.

CreatingaMasterDetailForm

IntheTableorviewfield,typeemployeesforthetablename,thenclickRefresh.Clicktherightdoublearrow
button
tomoveallavailablecolumnstotheDatabaseItemstobeincludedintheblock,thenclick
Next>.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

27/92

6/8/2015

CreatingaMasterDetailForm

5.

Becausethereisalreadyablockintheform,youareofferedtheoptiontorelatethisnewblocktoit.Click
CreateRelationship....Adialogdisplaysanyforeignkeysdefinedinthedatabasebetweenthesetwotables.
ClickOKtobasetherelationshipbetweentheblocksontheEMP_DEPT_FKforeignkey.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

28/92

6/8/2015

6.

CreatingaMasterDetailForm

ClickNext>toacceptthejoinconditioncreatedautomaticallybyFormsBuilderbasedontheforeignkey,then
onthenextscreenclickNext>,andthenFinish.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

29/92

6/8/2015

7.

CreatingaMasterDetailForm

IftheWelcometotheLayoutWizardpagedisplays,clickNext>.
ClickNext>toacceptthedefaultoflayingouttheitemsontheexistingcanvas.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

30/92

6/8/2015

8.

CreatingaMasterDetailForm

IntheAvailableItemscolumn,selectfordisplayallitemsexceptManager_IdandDepartment_Id,andthenclick
thesinglerightarrowbutton
tomovethemtotheDisplayedItemscolumn.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

31/92

6/8/2015

9.

CreatingaMasterDetailForm

Changethefollowingitemprompts:
Name

Prompt

EMPLOYEE_ID

ID

PHONE_NUMBER

Phone

COMMISSION_PCT

Commission%

ClickNext>.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

32/92

6/8/2015

CreatingaMasterDetailForm

10. Youwanttodisplayseveralemployeesatatimeinatabularformat,soselecttheTabularoptionandclickNext
>.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

33/92

6/8/2015

CreatingaMasterDetailForm

11. FortheFrameTitle,typeEmployees.ChangeRecordsDisplayedto5.CheckDisplayScrollbar,thenclick
Next>,andonthefinalscreen,clickFinish.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

34/92

6/8/2015

CreatingaMasterDetailForm

12. TheLayoutEditoropensshowinghowfiveemployeerecordsaredisplayed.IfyoumaximizetheLayoutEditor
window,youcanseethatthecanvashasbeenenlargedtoaccommodatealltheitems,buttheviewport,which
istheareathatshowsdataintherunningform,doesnotshowtheentirerecord.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

35/92

6/8/2015

CreatingaMasterDetailForm

Note:Althoughinthiscaseyoucouldenlargetheviewportsothattheentirerecordisvisible,forthisexercise
youuseadifferenttechniquethatshowsyouonewaytomakeitpossibleforuserstoviewmoredatathancan
displayinasinglewindow.

13. RestoretheLayoutEditorwindowtoitsoriginalsize.ObservethattheObjectNavigatorshowsthatarelation,
sometriggers,andsomeprogramunitshavebeenautomaticallycreated.Theseareformasterdetail
coordination.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

36/92

6/8/2015

CreatingaMasterDetailForm

14. ClickSave
Step1).

tosavetheform,thenclickRunForm

Whentheformstartsrunning,clickExecuteQuery

totestit(besurethatyouhavestartedOC4Jsee

todisplaydataintheform.ClickNextRecord

Noticethattheformautomaticallydisplaysemployeesassociatedwiththenextdepartmentrecord.ClickNext
Block
tonavigatetotheEmployeesblock.Youmusttabthroughtheitemstobeabletoseethemall.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

37/92

6/8/2015

CreatingaMasterDetailForm

Inthenextstep,youseeonetechniquetobetterdisplaydatathatdoesnotfitinasinglewindow.

15. ClickExitForm

toexittheapplication,thenclosethebrowserwindow.

Step5CreatingaNewCanvas
BacktoTopicList
Byrunningthemasterdetailform,youcanseethatFormshasalreadydonethejobofbuildingandcoordinatingthemaster
detailblocksforyou.Theformisusefulasitis,withonlythedefaultfunctionalitythatFormshasbuiltforyou.Intheremaining
steps,youmakeadjustmentstoenhancetheusabilityoftheform.Thefirstthingyoudoiscreateanewcanvastodisplay
mostofthedetailsaboutanemployee.
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

38/92

6/8/2015

CreatingaMasterDetailForm

Inadditiontothecontentcanvas,whichtakesupallthespaceinthewindow,youcancreatethreeothertypesofcanvases:
Stackedcanvas

Candisplayinfrontofacontentcanvasandisusuallysmallerthanthecontentcanvas

Tabcanvas

Specializedtypeofstackedcanvascontainingmultipletabpages

Toolbarcanvas

Canvasthatdisplaysaboveortotheleftofthecontentcanvas,typicallyusedforbuttons

YoudecidetocreateasecondcontentcanvasandmovesomeoftheitemsfromtheEmployeesblocktothatcanvas.In
addition,youdefineonthatsecondcanvassomeitemsthataresynchronizedwiththeitemsthatappearonthemaincanvas.
Tocreatethesecondcontentcanvas,movesomeoftheEmployeesblockitemstoit,andcreatesomesynchronizeditems,
performthefollowingsteps:
1.

2.

SelectthecanvasintheObjectNavigatorandclickCreate

ChangethenamesofbothcanvasesbyclickingthenameintheObjectNavigator,thenclickingagainand
overtypingtheexistingname.CalltheoriginalcanvasMAIN_CVandthenewcanvasEMP_DETAILS_CV.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

39/92

6/8/2015

CreatingaMasterDetailForm

Note:AlternativelyyoucouldchangethenameinthePropertyPalette.

3.

OpentheMAIN_CVcanvasintheLayoutEditor.IntheEmployeesblock,controlclick(ordragthemouse)to
selecttheEmail,Phone_Number,Hire_Date,Salary,andCommission_Pctitems.ChooseEdit|Cutfromthe
menu.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

40/92

6/8/2015

CreatingaMasterDetailForm

4.

SelecttheEMP_DETAILS_CVcanvasfromtheCanvaspopuplistatthetopleftoftheLayoutEditorandselect
EMPLOYEESfromtheBlockpopuplist.ChooseEdit|Pastefromthemenu.Dragtheitemstoalocationnear
theupperleftcornerofthecanvas.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

41/92

6/8/2015

5.

CreatingaMasterDetailForm

Withallitemsstillselected,openthePropertyPaletteandchangethefollowingproperties:
Property

Value

NumberofItemsDisplayed

PromptAttachmentEdge

Start

PromptAttachmentOffset

Thendragtheitemstoarrangethemonthecanvas,leavingsomeroomatthetopforthesynchronizeditems
thatyoucreatenext.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

42/92

6/8/2015

CreatingaMasterDetailForm

6.

Changethebackgroundcolorofthecanvas.ClickablankspotonthecanvassothatthePropertyPalette
displaysthecanvasproperties.ChangetheBackgroundColorpropertytoacolorofyourchoosing.

7.

SelectMAIN_CVfromtheCanvaspopuplistoftheLayoutEditor.SelecttogethertheEmployee_Id,
First_Name,andLast_Nameitems.Fromthemenu,chooseEdit|Copy.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

43/92

6/8/2015

CreatingaMasterDetailForm

8.

SelectEMP_DETAILS_CVfromtheCanvaspopuplistoftheLayoutEditor.Fromthemenu,chooseEdit|
Paste.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

44/92

6/8/2015

CreatingaMasterDetailForm

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

45/92

6/8/2015

9.

CreatingaMasterDetailForm

Changethepropertyvaluesasyoudidinstep55above,thenchangethenamesofeachoftheitemsto
M_EMPLOYEE_ID,M_FIRST_NAME,andM_LAST_NAME(theMisjustanindicationthattheseitemsmirror,orare
synchronizedwith,otheritems).
IntheSynchronizewithItempropertyforeachitem,selectfromthepoplisttheitemwithwhichthisitemshould
besynchronized.Forexample,M_Employee_IdshouldbesynchronizedwithEmployee_Id.
Changeotherindividualpropertiesasshown:
Item

Property

Value

M_EMPLOYEE_IDand Required
M_LAST_NAME

No

M_FIRST_NAMEand
M_LAST_NAME

Null
0

DataLengthSemantics
MaximumLength

Note:Ifyoufailtosetthese
properties,theformstill
functions,butyoureceive
annoyingmessageswhenyou
runtheformfromForms
Builder.Ifyouwouldprefernot
tosettheseproperties,youcan
ignorethemessages.

Dragtheitemstothetopofthecanvasandarrangethemnearthetop.

10. OpentheMAIN_CVcanvasagain.ToensurethatchangestothelayoutoftheEmployeesblockarepreserved,
clickitsFrame(thelinethatsurroundstheitemsintheEmployeesblock).InthePropertyPalettefortheFrame,
changethepropertyUpdateLayoutfromAutomaticallytoManually.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

46/92

6/8/2015

CreatingaMasterDetailForm

11. MovethescrollbarfromthefarrightoftheMAIN_CVcanvastoapositionjusttotherightoftheremainingitems,
thenresizetheframewidthappropriately.

12. ClickSave
Step1).

tosavetheform,thenclickRunForm

Whentheformstartsrunning,clickExecuteQuery

totestit(besurethatyouhavestartedOC4Jsee

todisplaydataintheform.ClickNextBlock

to

navigatetotheEmployeesblock.Youstillmusttabthroughtheitemstobeabletoseethemall,butatleastnow
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

47/92

6/8/2015

CreatingaMasterDetailForm

theemployeedetaildisplaysallinonewindow.Youmaynoticethatnavigationthroughtheitemsonthedetail
pageisnotwhatyoumightexpectyouchangethenavigationinalaterstep.

Note:Youcoulduseastackedcanvas,ratherthanacontentcanvas,todisplaytheemployeedetails.Ifyouhad
alargernumberofitems,youcoulduseatabcanvastodisplaythem,arrangingtheitemsondifferenttab
pages.

13. ClickExitForm

toexittheapplication,thenclosethebrowserwindow.

Step6CreatingaNewWindow
BacktoTopicList
Becauseyouhavetwocontentcanvasesandonewindow,youcandisplayonlyonecontentcanvasatatime.Bothcanvases
displayinWindow1thatFormsBuildercreatedbydefault.
Ifyouwouldliketoenableuserstoviewbothcanvasesatonce,youcancreateanotherwindow.Tocreateanewwindow
anddisplaytheEMP_DETAILS_CVcanvasinit,performthefollowingsteps:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

48/92

6/8/2015

CreatingaMasterDetailForm

1. SelectthewindowintheObjectNavigatorandclickCreate

2. ChangethenamesofbothwindowsbyclickingthenameintheObjectNavigator,thenclickingagainand
overtypingtheexistingname.CalltheoriginalwindowMAIN_WINandthenewwindowEMP_DETAILS_WIN.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

49/92

6/8/2015

CreatingaMasterDetailForm

Note:AlternativelyyoucouldchangethenameinthePropertyPalette.

3. InthePropertyPaletteforeachwindow,changeitsTitleproperty.Thischangesthetitlethatdisplaysineach
windowoftherunningform.
ChangethetitleforMAIN_WINtoDepartmentsandEmployees.ChangethetitleforEMP_DETAILS_WINto
EmployeeDetails.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

50/92

6/8/2015

CreatingaMasterDetailForm

4. SelecttheEMP_DETAILS_CVcanvasintheObjectNavigator.InthePropertyPalette,changeitsWindow
propertybyselectingEMP_DETAILS_WINfromthepopuplist.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

51/92

6/8/2015

CreatingaMasterDetailForm

5. IntheLayoutEditorfortheMAIN_CVcanvas,placeyourcursoratthepointwhereyouwantthenewwindowto
bedisplayed,andmakenoteoftheXandYcoordinatesshownatthebottomoftheLayoutEditorwindow.In
thiscase,theXandYcoordinatesare210and120.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

52/92

6/8/2015

CreatingaMasterDetailForm

6. InthePropertyPalettefortheEMP_DETAILS_WINwindow,settheXPositionandYPositionpropertiestothe
valuesoftheXandYcoordinatesinthepreviousstep.TheexampleshowssettingXPositionto210andY
Positionto120.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

53/92

6/8/2015

CreatingaMasterDetailForm

7. OpentheEMP_DETAILS_CVcanvasintheLayoutEditorandresizetheViewport(blackrectangle)sothatitis
justlargeenoughtodisplayalltheitems.YoumayneedtomaximizetheLayoutEditorwindowtobeableto
seetheoriginallowerrightpointoftheviewport.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

54/92

6/8/2015

CreatingaMasterDetailForm

Note:Resizingtheviewportactuallyresizesthewindowinwhichthecanvasisdisplayed.Itisavisualwayto
changetheheightandwidthpropertiesofthewindowwithouttheneedtochangethemdirectlyintheProperty
Palette.

8. ClickSave
Step1).

tosavetheform,thenclickRunForm

Whentheformstartsrunning,clickExecuteQuery

totestit(besurethatyouhavestartedOC4Jsee

todisplaydataintheform.ClickNextBlock

to

navigatetotheEmployeesblock.Tabthroughtheitemssothattheseparatewindowisinvoked.

Designsuggestion:Becauseyoucannowseethedetailsalongwiththemaincanvas,youmaydecideto
eliminatethesynchronizeditemsfromthedetailcanvas.
Itmayalsobehelpfultodifferentiatethecurrentrowonthemaincanvasvisually,suchasbyspecifyinga
differentbackgroundcolorforthecurrentitem.Youcandothisby:
Definingavisualattribute(seetheonlinehelptopicCreatingaNamedVisualAttribute)
SettingapropertyoftheEmployeesblockcalledCurrentRecordVisualAttributegrouptothenameofthe
visualattributethatyoudefined

9. ClickExitForm

toexittheapplication,thenclosethebrowserwindow.

Step7BuildingaControlBlock
BacktoTopicList
Althoughmostdatablocksarebasedontables,views,orstoredprocedures,youcancreateblocksthatarenotrelatedtothe
database.SuchblocksarereferredtoasControlBlocks.ControlBlockstypicallycontainbuttons,calculateditems,orother
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

55/92

6/8/2015

CreatingaMasterDetailForm

objectsthatpertaintotheformasawhole,ratherthanjustasingleblock.
Tocreateacontrolblocktodisplaythesumofdepartmentsalaries,performthefollowingsteps:
1.

SelecttheEmployeesblockintheObjectNavigatorandclickCreate

2.

SelecttheoptiontoBuildanewdatablockmanually,thenclickOK.

3.

InthePropertyPaletteforthenewblock,setNametoCONTROLandsetSingleRecordtoYes.TheSingle
RecordpropertyisappropriateforaControlBlockbecauseitdoesnotcontainmultiplerecords.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

56/92

6/8/2015

CreatingaMasterDetailForm

Note:SingleRecordmustbesettoYesforaControlBlockthatcontainsasummarycalculateditem.

4.

IntheLayoutEditor,opentheMAIN_CVcanvas.SelectCONTROLfromtheBlockpopuplist.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

57/92

6/8/2015

CreatingaMasterDetailForm

5.

ClicktheDisplayItemtool

,thenclickinthecanvastotherightoftheManageritem.

6.

UsingthePropertyPalette,setthefollowingpropertiesonthenewitem:
Property

Value

Name

SAL_SUM

DataType

Number

MaximumLength

14

FormatMask

$9,999,999.00

CalculationMode

Summary

SummaryFunction

Sum

SummarizedBlock

EMPLOYEES

SummarizedItem

Salary

Height

14

Prompt

TotalSalaries

PromptAttachmentEdge

Top

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

58/92

6/8/2015

CreatingaMasterDetailForm

7.

AsummarizedblockmusthaveitsQueryAllRecordsorPrecomputeSummariespropertysettoYessothatthe
sumincludesallrecords,notonlythosealreadyretrievedintotheblock.InthePropertyPaletteforthe
Employeesblock,setoneofthesepropertiestoYes.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

59/92

6/8/2015

CreatingaMasterDetailForm

8.

ClickSave

tosavetheform,thenclickRunForm

totestit(besurethatyouhavestartedOC4Jsee

Step1).
Whentheformstartsrunning,clickExecuteQuery

todisplaydataintheform.ClickNextRecord

to

navigatetoadepartmentwithmorethanoneemployee.
ClickNextBlock

tonavigatetotheEmployeesblock.Tabthroughtheitemssothattheseparatewindowis

invoked.
Whilethecursorisintheseparatewindow,clickNextRecord
verifythatthetotaldepartmentsalariesfigureiscorrect.

throughallexistingemployeerecordsand

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

60/92

6/8/2015

CreatingaMasterDetailForm

9.

ClickExitForm

toexittheapplication,thenclosethebrowserwindow.

Step8ControllingNavigation
BacktoTopicList
Asyouweretestingtheform,dependingonhowyouarrangedtheitemsyoumayhavenoticedthatthecursordidnotmovein
thedesiredsequencewhenyoutabbedthroughtheitems.Inaddition,youmaypreferthatwhenyoutaboutofthelastitemin
anEmployeesrecord,thatthecursorshouldmovetothenextrecord,andthatwhenyoutaboutofthelastitemina
Departmentsrecord,thatthecursorshouldmovetotheEmployeesblock.Inthisstep,youchangethenavigationorderso
thatthesethingsareaccomplished.
Tochangenavigationorder,performthefollowingsteps:
1.

Bydefault,navigationorderisdeterminedbythesequenceinwhichobjectsappearintheObjectNavigator.
OpentheEMP_DETAILS_CVcanvasintheLayoutEditor.IntheObjectNavigator,dragtheitemsinthe
Employeesblocktotheorderinwhichyouwantthenavigationtooccur.
Forexample,whenitemsarearrangedonthecanvasasshownbelow,youwantthecursortomoveto
HIRE_DATEwhenyoutaboutofPHONE_NUMBER.Tochangethesequence,youdragHIRE_DATEinthe
ObjectNavigatortothepositionjustafterPHONE_NUMBER.
IgnoretheitemsJOB_ID,MANAGER_ID,andDEPARTMENT_ID,becausethoseitemsarenotdisplayedon
anycanvas,sonavigationtothoseitemsdoesnotoccur.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

61/92

6/8/2015

2.

CreatingaMasterDetailForm

Youcanalsouseblockpropertiestoaffectnavigationorder.
InthePropertyPalettefortheDepartmentsblock,changetheNavigationStylepropertytoChangeData
Block.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

62/92

6/8/2015

CreatingaMasterDetailForm

3. InthePropertyPalettefortheEmployeesblock,changetheNavigationStylepropertytoChangeRecord.

4.

ClickSave

tosavetheform,thenclickRunForm

totestit(besurethatyouhavestartedOC4Jsee

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

63/92

6/8/2015

CreatingaMasterDetailForm

Step1).TestthatthenavigationorderisthesameaswhatyoudeterminedbymovingtheitemsintheObject
Navigator,thatthecursormovesintotheEmployeesblockwhenyoutaboutoftheDepartment_Nameitem,
andthatthecursormovestothenextEmployeesrecordwhenyoutaboutofthelastitemintheEmployees
block.
ClickExitForm

5.

toexittheapplication,thenclosethebrowserwindow.

Youcanalsoaffectnavigationwithitemproperties.
Inpreparationforsomenewfunctionalitythatyouimplementwithcodeinalaterstep,changethefollowing
itempropertiesintheEmployeesblock:
Item

Property

Value

EMPLOYEE_ID

PreviousNavigationItem

LAST_NAME

LAST_NAME

NextNavigationItem

EMPLOYEE_ID

Note:Whenviewingaqueriedrecord,thismakesitimpossibletonavigatetotheemployeedetailsshownon
theEMP_DETAILS_CVcanvas.Youaddtheabilitytonavigatetotheseitemsinalaterstep.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

64/92

6/8/2015

6.

CreatingaMasterDetailForm

ClickSave

tosavetheform.

Step9ModifyingtheLayout
BacktoTopicList
Whenyouattempttoinsertanewemployeerecord,youdiscoverthatyouhaveomittedarequireddatabasecolumn,JOB_ID,
fromthelayout.YoudidincludeJOB_IDinthedatablockitselfifyouhadnot,youcouldusetheDataBlockWizardin
reentrantmodetoaddtheJOB_IDtothedatablock.ToinvoketheDataBlockWizardinreentrantmode,youjustrightclick
theblockintheObjectNavigatorandchooseDataBlockWizardfromthecontextmenu.
Sothatitisbepossibletousetheformtoinsertemployeerecords,youcouldusetheLayoutWizardinreentrantmodetoadd
theitemtothelayoutforthatrequireddatabasecolumn.However,usingtheLayoutWizardarrangestheitemsintheir
originaltabularlayoutwithintheframeontheMAIN_CVcanvas,andthisisnotdesirableforthisapplication.Ifyouwanttotry
thistoseetheeffect,savetheformfirstsothatyoucanreverttothesavedcopy,thenrightclicktheEmployeesframeonthe
MAIN_CVcanvasandselectLayoutWizardfromthecontextmenutoopentheLayoutWizardinreentrantmode.Youcantell
thatyouareinreentrantmodebecausetherearetabsalongthetopoftheWizardandthereisanApplybuttonthatdoesnot
existunlesstheWizardisinreentrantmode.ThenontheDataBlocktab,moveJOB_IDtoDisplayedItemsandclickFinish.
Afteryouexperimentwiththis,closetheformwithoutsavingit(selecttheHRformintheObjectNavigatorandclickDelete),
thenreopenthesavedformtocontinue.
InsteadofusingtheLayoutWizardinreentrantmodetomodifythelayout,inthisstepyousimplychangethepropertiesofthe
JOB_IDitem.ToaddJOB_IDtotheEMP_DETAILS_CVcanvas,performthefollowingsteps:
1.

SelecttheJOB_IDitemintheObjectNavigatoranddisplayitsPropertyPalette.ChangeitsCanvasPropertyto
EMP_DETAILS_CV,changeNumberofItemsDisplayedto1,andchangePromptAttachmentOffsetto5.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

65/92

6/8/2015

2.

CreatingaMasterDetailForm

OpentheLayoutEditorfortheEMP_DETAILS_CVcanvas.TheJOB_IDitemisdisplayedintheupperleft
corner.Dragittothedesiredpositiononthecanvas.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

66/92

6/8/2015

3.

CreatingaMasterDetailForm

IntheObjectNavigator,dragtheJOB_IDitemtotheproperpositionforthedesirednavigationorder.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

67/92

6/8/2015

CreatingaMasterDetailForm

4.

ClickSave

tosavetheform,thenclickRunForm

totestit(besurethatyouhavestartedOC4Jsee

Step1).
Beforequeryinganydata,attempttoinsertanewDepartmentsrecord.Enter99fortheDepartment_Idand
TestfortheDepartment_Name.ClickSave
.Therecordshouldbeinsertedwithouterror.

5.

ClickRemoveRecord

todeletetherecordthatyoujustinserted,thenclickSave

.Therecordshould

bedeletedwithouterror.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

68/92

6/8/2015

CreatingaMasterDetailForm

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

69/92

6/8/2015

6.

CreatingaMasterDetailForm

ClickExecuteQuery

.NavigatetotheEmployeesblockandclickInsertRecord

Enter999fortheEmployee_ID,andenteryourownfirstandlastname.ClickSave

.
.

Becausetherearesomerequireditemsthathavenovalues,youreceiveanerrorandFormsautomatically
navigatestothefirstnullrequireditem.EnterIT_PROGfortheJob_Id,thenfillinanyvaluesyoudesireforthe
otheritems.ThenclickSave
.TherecordshouldbesavedsuccessfullynoticethattheTotalSalaries
amountisrecalculatedautomatically.Youmaydeletethenewrecordifdesired.

ClickExitForm

toexittheapplication,thenclosethebrowserwindow.

Step10AddingFunctionalitywithCode
BacktoTopicList
Nowyouhaveafullyfunctionalmasterdetailformthatenablesyoutoquery,insert,update,anddeleterecords.Theform
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

70/92

6/8/2015

CreatingaMasterDetailForm

evenperformscalculationsautomatically,andyouhavenotwrittenasinglelineofcodetoachievethisfunctionality.Forms
Buildermakesiteasytodeclarativelydevelopacompleteapplication.
However,youmaydesiretoaddfunctionalitybycodingPL/SQLprogramunitsandtriggersinyourform.Atriggerisablockof
codethatexecutesinresponsetoacertainaction,suchaswhentheuserclicksabutton.
Inthisstep,youwritecodetoperformthefollowing:
Executeaqueryautomatically
Populatenonbasetableitemswhenquerying
Uselistsofvaluesforuserinput
Createabuttontodisplaydetails
Adjustnavigationprogrammatically
Closeawindowprogrammatically

ExecuteaQueryAutomatically
BacktoList
Itiscommonfortheusertowantdatatobedisplayedintheformwhenitfirstopens.Toexecuteaqueryautomaticallywhen
theformstarts,performthefollowingsteps:
1.

IntheObjectNavigator,rightclicktheformlevelTriggersnode,thenselectSmartTriggers|WHENNEW
FORMINSTANCEfromthecontextmenu.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

71/92

6/8/2015

2.

CreatingaMasterDetailForm

ThePL/SQLEditoropensupfortheformlevelWhenNewFormInstancetrigger.Enterthefollowingcode:
DO_KEY('EXECUTE_QUERY')
ThenclickCompile

inthePL/SQLEditor.Amessageshowingthatthetriggeriscompileddisplaysinthe

lowerrightcorneroftheeditor.

ClickSave

PopulateNonBaseTableItemsWhenQuerying
BacktoList
Onewaytolookuprelateddataanddisplayitautomaticallyinnonbasetableitemsistouseapostquerytrigger.This
techniquerequiresaroundtriptothedatabaseforeachrowthatisretrievedbythequery,soitcanresultinslower
performance.Foralargenumberofrecords,youmaywanttoconsiderbasingthetableonavieworonasetofstored
procedures,whichmayprovidebetterperformance.
Toautomaticallypopulatethenonbasetableitemswhenquerying,performthefollowingsteps:
1.

UndertheDepartmentsblockintheObjectNavigator,selecttheTriggersnode,thenclickCreate

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

72/92

6/8/2015

2.

3.

CreatingaMasterDetailForm

TypepintheFindbox,thenselectPOSTQUERYfromthelist.ClickOK.

ThePL/SQLEditoropensupfortheblocklevelPostQuerytriggerfortheDepartmentsblock.ThePostQuery
triggerfiresforeveryrowthatisretrievedbyaqueryoftheDepartmentsblock.Enterthefollowingcode:
SELECTCITY||','||STATE_PROVINCE||','

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

73/92

6/8/2015

CreatingaMasterDetailForm

||COUNTRY_ID
INTO:departments.location
FROMlocations
WHERE:departments.location_id=location_id
SELECTFIRST_NAME||''||LAST_NAME
INTO:departments.manager
FROMemployees
WHERE:departments.manager_id=employee_id
ThenclickCompile

inthePL/SQLEditor.Amessageshowingthatthetriggeriscompileddisplaysinthe

lowerrightcorneroftheeditor.

ClickSave

UseListsofValuesforUserInput
BacktoList
AListofValues(LOV)canbeattachedtoanyinputitemtohelpuserstoenteraccuratedata.Thereislittlecodinginvolvedin
defininganLOVotherthantypingintheSELECTstatementtouse.
YoucoulduseLOVsforLocationandManager,thenpopulatethosenonbasetableitemsalongwiththeirassociatedbase
tableitems,Location_IdandManager_Id.However,inthisexample,youuseanLOVtoenabletheusertoselectavalid
Job_Idforanemployee.
TodefineanLOVfortheJob_Iditem,performthefollowingsteps:
1.

ClicktheLOVsnodeintheObjectNavigator,thenclickCreate

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

74/92

6/8/2015

CreatingaMasterDetailForm

2.

LeavetheUsetheLOVWizardoptionselectedandclickOK.

3.

OnthefirstpageoftheLOVWizard,clickNexttobasetheLOVonanewrecordgroupbasedonaquery.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

75/92

6/8/2015

CreatingaMasterDetailForm

4.

FortheSQLQueryStatement,enterthefollowing:
SELECTjob_titleTITLE,job_idID
FROMjobs
ORDERBYjob_title
Donotendthestatementwithasemicolon.
Ifyouwanttoensurethatthestatementissyntacticallycorrect,clickCheckSyntax.Youshouldreceivea
messageaffirmingthecorrectnessofthestatementclickOKtodismissthismessage,thenintheLOVWizard,
clickNext.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

76/92

6/8/2015

5.

CreatingaMasterDetailForm

IntheLOVyouwanttodisplaytheJob_Titletotheuser,becausethiscontainsinformationthatismeaningfulto
theuser.YoudecidetoalsodisplaytheJob_Id.Clickthedoublerightarrowbutton
tomovebothrecord
groupcolumnstotheLOV,thenclickNext.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

77/92

6/8/2015

6.

CreatingaMasterDetailForm

WhatyouaretryingtoaccomplishistopopulatetheJob_IditemintheEmployeesblockwiththeIDselected
fromthequery.
ClicktheReturnvaluecolumnfortheIDcolumn,thenclickLookupreturnitem....IntheItemsandParameters
list,select:EMPLOYEES.JOB_ID,thenclickOK.
CheckAutomaticallysizecolumns,thenclickNext.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

78/92

6/8/2015

7.

CreatingaMasterDetailForm

EnterJobsfortheLOVTitle,250fortheWidth,and300fortheHeight.ClickNext.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

79/92

6/8/2015

8.

CreatingaMasterDetailForm

ClickNexttoacceptthedefaultsofretrieving20rowsatatimeandrefreshingtherecordgroupbefore
displayingtheLOV.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

80/92

6/8/2015

9.

CreatingaMasterDetailForm

YouwanttheLOVtobeavailablefromtheJob_IDitemintheEmployeesblock.Clicktherightarrowbutton
tomoveEMPLOYEES.JOB_IDfromReturnItemstoAssignedItems,thenclickNext,andonthefinal
screen,clickFinish.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

81/92

6/8/2015

CreatingaMasterDetailForm

ClickSave

CreateaButtontoDisplayDetails
BacktoList
BecausethereisnownoeasywaytonavigatetoitemsontheEMP_DETAILS_CVcanvas,youcreateabuttonenabling
userstodoso.
Inmostcases,youwouldcreatebuttonsintheControlblock.However,thebuttonneedstoknowwhichrecordinthe
Employeesblocktodisplaydetailsfor,andtheeasiestwaytodothis(thereareotherways)istoplacethebuttoninthe
Employeesblock.
Formostbuttons,yousettheMouseNavigatepropertytoNo.Inthiscase,however,youwanttoselectanemployeerecord
anddisplayitsdetailswithoneclick,soyouleaveMouseNavigatesettoitsdefaultvalue,whichisYes.
Tocreateabuttontodisplayemployeedetails,performthefollowingsteps:
1.

OpentheLayoutEditorfortheMAIN_CVcanvas.EnlargetheEmployeesframetotherightbyselectingitand
draggingitsresizehandle.Movethescrollbartotherightsideoftheframe.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

82/92

6/8/2015

2.

CreatingaMasterDetailForm

SelectEMPLOYEESfromtheblocklistintheLayoutEditor.ClicktheButtontoolintheLayoutEditor,thenclick
intheareabetweenLast_Nameandthescrollbar.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

83/92

6/8/2015

CreatingaMasterDetailForm

3.

OpenthePropertyPaletteforthebuttonandsetthefollowingproperties:
Property

Value

Name

DETAILS_BTN

Label

Details

Width

50

Height

14

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

84/92

6/8/2015

4.

CreatingaMasterDetailForm

IntheObjectNavigator,dragthebuttontoapositionjustafterLast_Name.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

85/92

6/8/2015

5.

CreatingaMasterDetailForm

RightclicktheDETAILS_BTNbutton,andfromthecontextmenuchooseSmartTriggers|WHENBUTTON
PRESSED.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

86/92

6/8/2015

6.

CreatingaMasterDetailForm

InthePL/SQLEditor,enterthefollowingcode:
GO_ITEM('job_id')
ClickCompile

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

87/92

6/8/2015

CreatingaMasterDetailForm

ClickSave

AdjustNavigationProgrammatically
BacktoList
YoupreviouslysettheNavigationStylepropertyoftheEmployeesblocktoChangeRecord,whichmeansthatwhentheuser
tabsoutofthelastitemintheblock,thecursorgoestothefirstiteminthenextrecord.However,becauseLast_Nameisnot
thelastitemintheblock,tabbingoutofitsimplynavigatestotheEmployee_Idofthesamerecord.
Toadjustnavigationsothattabbingfromtheemployee'slastnamenavigatestothenextrecord,performthefollowingsteps:
1.

2.

IntheObjectNavigator,expandtheLast_NamenodeundertheEmployeesblock,andselecttheTriggers
node.ClickCreate
.

IntheTriggerswindow,scrolldownandselectKEYNEXTITEM,thenclickOK.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

88/92

6/8/2015

CreatingaMasterDetailForm

3.

InthePL/SQLEditor,enterthefollowingcode,thenclickCompile

do_key('next_record')

ClickSave

CloseaWindowProgrammatically
BacktoList
WhentheuserclickstheXonaFormswindowtocloseit,bydefaultnothinghappens.Ifyouwanttheusertobeabletoclose
thewindow,youmustcodetheactiontotake.
ToclosetheEMP_DETAILS_WINwindowwhentheuserclickstheX,performthefollowingsteps:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

89/92

6/8/2015

1.

CreatingaMasterDetailForm

SelecttheTriggersnodeundertheHRform,clickCreate

,andchooseWHENWINDOWCLOSEDfrom

thetriggerlist,thenclickOK.

2.

InthePL/SQLEditor,enterthefollowingcode,thenclickCompile:
IF:SYSTEM.CURSOR_ITEMIN('EMPLOYEES.M_EMPLOYEE_ID',
'EMPLOYEES.M_FIRST_NAME',
'EMPLOYEES.M_LAST_NAME',
'EMPLOYEES.JOB_ID',
'EMPLOYEES.EMAIL',
'EMPLOYEES.PHONE_NUMBER',
'EMPLOYEES.HIRE_DATE',
'EMPLOYEES.SALARY',
'EMPLOYEES.COMMISSION_PCT')THEN
GO_ITEM('employee_id')
HIDE_WINDOW('emp_details_win')
ENDIF

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

90/92

6/8/2015

CreatingaMasterDetailForm

ClickSave

3.

ClickRunForm

totestit(besurethatyouhavestartedOC4JseeStep1).

Demonstratethat:
Theformdisplaysthedata(executesthequery)automatically.
TheLocationandManageritemsarepopulatedautomatically.
WhennavigatingintheEmployeesblockontheMaincanvas,tabbingoutofLast_Namenavigatestothe
nextemployeerecord.
EmployeedetailsdisplaywhenyouclickDetailsintheEmployeesblock.
IntheJob_IditemyoucandisplayandselectfromanLOVwhenyoupressCtrl+L,andtheJob_Iditemis
populatedwiththejobthatyouselect.
Youcanclosethedetailwindow.
ClickExitForm

toexittheapplication,thenclosethebrowserwindow.

Summary
BacktoTopicList
ThisexerciseshowedyouhoweasyitistocreateamasterdetailformusingtheDataBlockandLayoutWizardsinForms
Builder.Youalsomanuallycreatedacontrolblockonwhichyouplacedanitemtoautomaticallycalculatethesumofsalaries
foradepartment.
Youenhancedadatablockwithnonbasetableitemstodisplaydatafromrelatedtables,andyoumovedsomeitemstoa
newcanvastodisplayinaseparatewindow.Youadjustednavigationandaddedanotherbasetableitemtothelayout.This
fullyfunctionalmasterdetailformwasachievedusingonlythevisualanddeclarativeIDEofFormsBuilder.
Youthenaddedcodetoexecuteaqueryautomatically,populatethenonbasetableitems,definealistofvaluestoaiduser
input,createabuttontodisplayemployeedetails,furtherrefinenavigationprogrammatically,andprogrammaticallyclosethe
http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

91/92

6/8/2015

CreatingaMasterDetailForm

separatewindow.
ThisbriefoverviewonlyscratchesthesurfaceofwhatyoucanaccomplishwithFormsBuilder.Formoreinformation,see
RelatedTopicsbelow.

Relatedtopics
OracleEducationcourses:OracleFormsDeveloper10g:MovetotheWeb
OracleEducationcourses:OracleFormsDeveloper10g:BuildInternetApplications
OTN:FormsProductspage

Moveyourmouseoverthisicontohideallscreenshots

http://www.oracle.com/webfolder/technetwork/tutorials/obe/forms/FormsMasterDetail/FormsMasterDetailOBE.htm

92/92

Вам также может понравиться