Top Banner
Creating a MasterDetail Form Purpose In this lesson you learn how to create a basic masterdetail Form with Oracle Forms Builder 10g. Topics This lesson discusses the following: Overview Prerequisites Step 1 Setting Up the Development Environment Step 2 Building a Data Block Step 3 Adding Non Base Table Items to a Data Block Step 4 Building a Detail Block Step 5 Creating a New Canvas Step 6 Creating a New Window Step 7 Building a Control Block Step 8 Controlling Navigation Step 9 Modifying the Layout Step 10 Adding Functionality with Code Summary Time to complete This lesson takes approximately 75 minutes to complete. Viewing Screenshots Move your mouse over this icon to show all screenshots. You can also move your mouse over each individual icon to see only the screenshot associated with it. Overview The lesson guides you through many of the tasks that you must perform when using Oracle Forms Builder to create a master detail form. You use the Data Block Wizard to quickly generate the master and detail blocks, then you add a control block (one with no base table items) to the form. You add some non base table items to the data blocks, and use PL/SQL triggers to add functionality to the form. Back to Topic List Scenario You are designing a human resource application. One of the main forms in this application is intended to enable HR clerks to maintain department and employee information. You have decided to implement this as a masterdetail form that displays one department with all employees in the department. Prerequisites Back to Topic List
92

Creating a Master-Detail Form

Sep 13, 2015

Download

Documents

MudassarSalfi

Provides the ful detail about master detail forms creation in oracle 10g
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 6/8/2015 CreatingaMasterDetailForm

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

    CreatingaMasterDetailForm

    Purpose

    InthislessonyoulearnhowtocreateabasicmasterdetailFormwithOracleFormsBuilder10g.

    Topics

    Thislessondiscussesthefollowing:

    OverviewPrerequisitesStep1SettingUptheDevelopmentEnvironmentStep2BuildingaDataBlockStep3AddingNonBaseTableItemstoaDataBlockStep4BuildingaDetailBlockStep5CreatingaNewCanvasStep6CreatingaNewWindowStep7BuildingaControlBlockStep8ControllingNavigationStep9ModifyingtheLayoutStep10AddingFunctionalitywithCodeSummary

    Timetocomplete

    Thislessontakesapproximately75minutestocomplete.

    ViewingScreenshots

    Moveyourmouseoverthisicontoshowallscreenshots.Youcanalsomoveyourmouseovereachindividualicontoseeonlythescreenshotassociatedwithit.

    Overview

    ThelessonguidesyouthroughmanyofthetasksthatyoumustperformwhenusingOracleFormsBuildertocreateamasterdetailform.YouusetheDataBlockWizardtoquicklygeneratethemasteranddetailblocks,thenyouaddacontrolblock(onewithnobasetableitems)totheform.Youaddsomenonbasetableitemstothedatablocks,andusePL/SQLtriggerstoaddfunctionalitytotheform.

    BacktoTopicList

    Scenario

    Youaredesigningahumanresourceapplication.OneofthemainformsinthisapplicationisintendedtoenableHRclerkstomaintaindepartmentandemployeeinformation.Youhavedecidedtoimplementthisasamasterdetailformthatdisplaysonedepartmentwithallemployeesinthedepartment.

    Prerequisites

    BacktoTopicList

  • 6/8/2015 CreatingaMasterDetailForm

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

    Inorderforthislessontoworksuccessfully,youneedtohaveperformedthefollowing:

    1. InstallOracleDeveloperSuite10g.

    2. Installthesampleschemastouseinthislesson.SeeInstallingtheSampleSchemasandEstablishinga

    DatabaseConnection.

    YoudonotneedtocreateadatabaseconnectioninJDeveloperjusthavetheHRschemaavailablesothatyoucanconnecttoitinForms.Ensurethatthetnsnames.orafileintheNetwork\AdmindirectoryoftheDeveloperSuiteinstallationcontainsanentrytoconnecttothedatabasewheretheHRschemaisavailable.

    Step1SettingUptheDevelopmentEnvironment

    BacktoTopicList

    OracleDeveloperSuite10gincludesastandaloneversionofOracle10gContainersforJ2EE(OC4J),whichyoucanuseasaWeblistenerandaservletcontainertotestFormsapplications.Togetreadytobuildandtestaform,performthefollowingsteps:

    1. FromtheWindowsStartmenu,selectPrograms|OracleDeveloperSuiteiDS10g|FormsDeveloper|StartOC4JInstance.

    2. Youcanminimizethecommandpromptwindowwhenthewindowdisplaysthemessage"OracleApplication

    ServerContainersforJ2EE10g(9.0.4.0.0)initialized".

    Moveyourmouseoverthisicontoseetheimage

    Note:DonotclosetheOC4JInstancewindow.WhenyouwanttostopOC4J,choosePrograms|OracleDeveloperSuiteiDS10g|FormsDeveloper|StopOC4JInstancefromtheWindowsStartmenu.

    3. FromtheWindowsStartmenu,selectPrograms|OracleDeveloperSuiteiDS10g|FormsDeveloper|Forms

    Builder.

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. WhenFormsBuilderstarts,anemptyformisautomaticallycreatednamedModule1.SelecttheModule1name,

    thenclickitagaintochangethenameoftheform.TypeinthenameHRandpressEnter.

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. ClickSave .Bydefault,Formssavesfilesinthe\bindirectoryofyourDeveloperSuiteinstallation.You

    maywanttosaveitinadifferentdirectoryifdesired,youcancreateanewdirectorycalledMyFormsinwhichtosavetheapplication.

    6. ConnecttothedatabaseastheHRuserbyclickingConnect andthenenteringtheuserid,password,andconnectstringforthedatabasethatcontainstheHRorHR8schema(seePrerequisites).

  • 6/8/2015 CreatingaMasterDetailForm

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

    Step2BuildingaDataBlock

    BacktoTopicList

    Transactionalapplicationsneedtobeabletoinsert,update,anddeleterecordsfromthedatabase.ThedatablockisthemechanismthatmakesthispossibleinaFormsapplication.Adatablockisalogicalgroupingofitemsthatusuallyareassociatedwithasingledatabasetable,view,orsetofstoredprocedures,althoughthedatablockmaycontainnonbasetableitemsalso.

    FormsBuilderincludesaDataBlockWizardtomakeitpossibletoeasilycreateadatablockandaLayoutWizardtolayouttheitemsontheform'scanvas.TousetheDataBlockWizardandtheLayoutWizardtocreateadatablockanddefineitslayout,performthefollowingsteps:

    1. SelecttheDataBlocksnodeintheObjectNavigator,thenclickCreate .

  • 6/8/2015 CreatingaMasterDetailForm

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

    2. IntheNewDataBlockdialog,ensurethatUsetheDataBlockWizardisselected,thenclickOK.

    3. IftheWelcometotheDataBlockWizardpagedisplays,clickNext>.

    Youcanbaseadatablockonadatabasetableorview,oronasetofstoredproceduresinwhichyoucandefinecomplicatedquery,insert,update,anddeletelogic.Forthisapplicationyoubasetheblockonatable,soensurethatTableorViewisselected,thenclickNext>.

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. IntheTableorviewfield,typedepartmentsforthetablename,thenclickRefresh.Clicktherightdoublearrowbutton tomoveallavailablecolumnstotheDatabaseItemstobeincludedintheblock,thenclickNext>.

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. Acceptthedefaultnamefortheblock,whichisthesameasthetablename,andclickNext>.

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. OnthefinalpageoftheDataBlockWizard,clickFinishtocreatethedatablockandinvoketheLayoutWizard.

  • 6/8/2015 CreatingaMasterDetailForm

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

    7. IftheWelcometotheLayoutWizardpagedisplays,clickNext>.

    AcceptthedefaultsandclickNext>tolayouttheitemsonanewcontentcanvas.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Note:Acontentcanvasisonethatfillstheentirewindow.Youcandisplayonlyonecontentcanvasatatimewithinawindow.Othercanvastypesaretoolbar,stacked,andtabcanvases,whichtypicallyresideinaportionofawindowwhilethecontentcanvasremainsatleastpartiallyvisible.

    8. Youdecidetodisplayonlythedepartmentidanddepartmentname,becausethelocationidandmanagerid

    arejustnumbersthatarenotmeaningfultotheuser.

    ControlclickDEPARTMENT_IDandDEPARTMENT_NAMEintheAvailableItemslist,thenclicktherightsinglearrowbutton tomovethemtotheDisplayedItemslist.

  • 6/8/2015 CreatingaMasterDetailForm

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

    ClickNext>.

    9. ClickNext>toacceptthedefaultitemprompt,width,andheightforbothitems.

  • 6/8/2015 CreatingaMasterDetailForm

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

    10. ClickNext>toaccepttheFormlayout.

  • 6/8/2015 CreatingaMasterDetailForm

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

    11. FortheFrameTitleenterDepartment,thenclickNext>.

  • 6/8/2015 CreatingaMasterDetailForm

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

    12. OnthefinalpageoftheLayoutWizard,clickFinishtocreatethecanvasandopenitintheLayoutEditor.

  • 6/8/2015 CreatingaMasterDetailForm

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

    13. IntheLayoutEditor,youcanperformanycosmeticchangesthatyouwanttothelayout.

    First,toensurethatchangestothelayoutframearepreserved,doubleclicktheframe(thelinethatsurroundstheitems)toinvokeitsPropertyPalette.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Note:YoucanleavethePropertyPaletteopenitdisplaysthepropertiesforwhateverobjectiscurrentlyselected.IfyoushouldclosethePropertyPalette,youcanreopenitbyselectingTools|PropertyPalettefromtheFormsBuildermenu.Alternatively,doubleclickingmostFormsobjectsopensthePropertyPaletteforthatobject.

    14. InthePropertyPalettefortheFrame,changethepropertyUpdateLayoutfromAutomaticallytoManually.

  • 6/8/2015 CreatingaMasterDetailForm

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

    15. Enlargetheframebyclickingthehandleinitslowerrightcorneranddraggingitdownwardandtotheright.

  • 6/8/2015 CreatingaMasterDetailForm

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

    16. ClicktheRoundedRectangletool onthetoolbarattheleftoftheLayoutEditor.Withthemouse,clickanddragarectanglearoundthedepartmentidandthedepartmentname.

    17. WiththerectangleselectedintheLayoutEditor,clickFillColor ontheLayoutEditortoolbarandpicka

    colorfortherectangle.(Youmayneedtoclickthearrow atthebottomofthetoolbartoscrolldowntotheFillColorbuttoniftheLayoutEditorwindowistoosmalltodisplayallthetools.)

    18. ClickSave tosaveyourform.

    Step3AddingNonBaseTableItemstoaDataBlock

    BacktoTopicList

    TheDepartmentsblockisbasedontheDepartmentsdatabasetable,andsofaralltheitemsintheblockrepresentcolumnsinthattable.However,thereisoftenaneedtoincludeitemsintheblockthatarenotinthebasetablefortheblock.Onecommonuseofnonbasetableitemsistodisplayinformationfromrelatedtables.

    TheDepartmentsblockcontainstwoitemsthatdonotappearonthecanvas:Manager_IdandLocation_Id.YoucanseetheseitemsintheObjectNavigator.Insteadofdisplayingthesenumberswhicharenotmeaningfultotheuser,youwanttodisplaythemanager'snameandthelocationcity,state/province,andcountry.

    Toaddnonbasetableitemstodisplayrelatedinformation,performthefollowingsteps:

  • 6/8/2015 CreatingaMasterDetailForm

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

    1. IntheLayoutEditor,clicktheDisplayItemtool .ClickapointonthecanvasjustbelowthedepartmentnametocreateaDisplayItem.ThenclicktheDisplayItemtoolagain,andclickapointonthecanvasjustbelowthedisplayitemthatyoujustcreated.

    Note:ADisplayItemissimilartoaTextItem(usedforDepartment_IdandDepartment_Name),exceptthatitdoesnotacceptuserinput.Ifyouwantuserstobeabletochangethesevalues,youshoulduseaTextItem.

    2. ControlclickeachoftheDisplayItemstoselectthemboth.Alternatively,youcandragthemousearoundboth

    itemstoselectthem,beingcarefultoincludeonlythosetwoitems.

  • 6/8/2015 CreatingaMasterDetailForm

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

    3. ThePropertyPaletteshouldnowdisplaythepropertiesforbothdisplayitems.Ifbothdisplayitemshavethesamevalueforaproperty,thevalueisdisplayed.Ifthetwodisplayitemshavedifferentvaluesforaproperty,asterisksaredisplayedforthatproperty.

    Selectingbothdisplayitemsenablesyoutochangepropertiestoidenticalvaluesforbothitems.

    ChangethefollowingpropertiesinthePropertyPaletteforbothdisplayitems:

    Property ValueMaximumLength 65DatabaseItem NoHeight 14PromptAttachmentOffset 5

    Hint:Ifyouhavetroublelocatingaparticularproperty,typeitsnameintheFindboxatthetoprightofthePropertyPalette.Assoonasyouhavetypedenoughletterstouniquelyidentifytheproperty,FormsBuilderhighlightsthatpropertyinthePropertyPalette.

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. Changethefollowingpropertiesforonlythefirstdisplayitembyselectingitsingly(clickanareaoutsidethetwo

    displayitemstodeselectthem,thenclickthefirstdisplayitem):

    Property ValueName LOCATIONPrompt Location

    Changethefollowingpropertiesfortheseconddisplayitemonly:

    Property ValueName MANAGERPrompt Manager

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. MovethesecondDisplayItemupslightlysoitisjustunderthefirst.Aneasywaytomoveanitemashort

    distanceistoselectitandthenusethearrowkeystonudgetheitemtoitsdesiredposition.

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. Toensurethatallitemsareproperlyaligned,selectallitems(donotincludethepromptsinthisselection)andclickAlignLeft ontheLayoutEditortoolbar.

    7. IntheLayoutEditor,clickintotheitempromptsDepartmentNameandDepartmentId.Deletetheword

    "Department"frombothprompts.Alternatively,youcanchangetheitempromptsinthePropertyPaletteforeachitem.

  • 6/8/2015 CreatingaMasterDetailForm

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

    8. ClickSave tosavetheform,thenclickRunForm totestit(besurethatyouhavestartedOC4JseeStep1).

    Whentheformstartsrunning,clickExecuteQuery todisplaydataintheform.ClickNextRecord and

    PreviousRecord tonavigatebetweenrecords.

    Note:AtthispointtheLocationandManageritemsarenotpopulatedyouwritecodetopopulatetheseitemsinalaterstep.

    9. ClickExitForm toexittheapplication,thenclosethebrowserwindow.

    CAUTION:AlwaysexittheapplicationbyclickingtheExitFormbuttonpriortoclosingthebrowser.FailuretodothismaycausetheRunformprocesstohangifthishappens,youneedtoopenTaskManagerandendtheifweb90.exeprocess.

    Step4BuildingaDetailBlock

  • 6/8/2015 CreatingaMasterDetailForm

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

    BacktoTopicList

    FormsDevelopergivesyoutheabilitytoquicklydefineadditionaldatablocks.TheDataBlockWizardoffersyoutheoptionofdefiningrelationsbetweenthenewblocksandanyexistingblocksintheform.

    NowthatyouhaveaDepartmentsblock,youwouldliketobeabletoadditionallydisplayalltheemployeesineachdepartment.TocreateadetailblockbasedontheEmployeestable,performthefollowingsteps:

    1. SelectDepartmentsintheObjectNavigator,thenclickCreate .ThisensuresthatthenewblockimmediatelyfollowsDepartmentsintheObjectNavigatortree.Thesequenceoftheblocksdeterminesdefaultnavigationandalsothesequenceofcommitprocessing.

    Note:Ifyouhappentocreateanobjectinthewrongorder,youcandragitsicontothedesiredpositionintheObjectNavigator.Forexample,ifthesequenceoftheblocksisEmployees,thenDepartments,youcandragtheEmployeesblockicontoapositionafterDepartmentsundertheDataBlocksnode.

    2. IntheNewDataBlockdialog,ensurethatUsetheDataBlockWizardisselected,thenclickOK.

    3. IftheWelcometotheDataBlockWizardpagedisplays,clickNext>.

    Youarebasingtheblockonatable,soensurethatTableorViewisselected,thenclickNext>.

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. IntheTableorviewfield,typeemployeesforthetablename,thenclickRefresh.Clicktherightdoublearrow

    button tomoveallavailablecolumnstotheDatabaseItemstobeincludedintheblock,thenclickNext>.

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. Becausethereisalreadyablockintheform,youareofferedtheoptiontorelatethisnewblocktoit.ClickCreateRelationship....Adialogdisplaysanyforeignkeysdefinedinthedatabasebetweenthesetwotables.ClickOKtobasetherelationshipbetweentheblocksontheEMP_DEPT_FKforeignkey.

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. ClickNext>toacceptthejoinconditioncreatedautomaticallybyFormsBuilderbasedontheforeignkey,then

    onthenextscreenclickNext>,andthenFinish.

  • 6/8/2015 CreatingaMasterDetailForm

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

    7. IftheWelcometotheLayoutWizardpagedisplays,clickNext>.

    ClickNext>toacceptthedefaultoflayingouttheitemsontheexistingcanvas.

  • 6/8/2015 CreatingaMasterDetailForm

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

    8. IntheAvailableItemscolumn,selectfordisplayallitemsexceptManager_IdandDepartment_Id,andthenclick

    thesinglerightarrowbutton tomovethemtotheDisplayedItemscolumn.

  • 6/8/2015 CreatingaMasterDetailForm

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

    9. Changethefollowingitemprompts:

    Name PromptEMPLOYEE_ID IDPHONE_NUMBER PhoneCOMMISSION_PCT Commission%

    ClickNext>.

  • 6/8/2015 CreatingaMasterDetailForm

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

    10. Youwanttodisplayseveralemployeesatatimeinatabularformat,soselecttheTabularoptionandclickNext>.

  • 6/8/2015 CreatingaMasterDetailForm

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

    11. FortheFrameTitle,typeEmployees.ChangeRecordsDisplayedto5.CheckDisplayScrollbar,thenclick

    Next>,andonthefinalscreen,clickFinish.

  • 6/8/2015 CreatingaMasterDetailForm

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

    12. TheLayoutEditoropensshowinghowfiveemployeerecordsaredisplayed.IfyoumaximizetheLayoutEditor

    window,youcanseethatthecanvashasbeenenlargedtoaccommodatealltheitems,buttheviewport,whichistheareathatshowsdataintherunningform,doesnotshowtheentirerecord.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Note:Althoughinthiscaseyoucouldenlargetheviewportsothattheentirerecordisvisible,forthisexerciseyouuseadifferenttechniquethatshowsyouonewaytomakeitpossibleforuserstoviewmoredatathancandisplayinasinglewindow.

    13. RestoretheLayoutEditorwindowtoitsoriginalsize.ObservethattheObjectNavigatorshowsthatarelation,

    sometriggers,andsomeprogramunitshavebeenautomaticallycreated.Theseareformasterdetailcoordination.

  • 6/8/2015 CreatingaMasterDetailForm

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

    14. ClickSave tosavetheform,thenclickRunForm totestit(besurethatyouhavestartedOC4Jsee

    Step1).

    Whentheformstartsrunning,clickExecuteQuery todisplaydataintheform.ClickNextRecord .Noticethattheformautomaticallydisplaysemployeesassociatedwiththenextdepartmentrecord.ClickNextBlock tonavigatetotheEmployeesblock.Youmusttabthroughtheitemstobeabletoseethemall.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Inthenextstep,youseeonetechniquetobetterdisplaydatathatdoesnotfitinasinglewindow.

    15. ClickExitForm toexittheapplication,thenclosethebrowserwindow.

    Step5CreatingaNewCanvas

    BacktoTopicList

    Byrunningthemasterdetailform,youcanseethatFormshasalreadydonethejobofbuildingandcoordinatingthemasterdetailblocksforyou.Theformisusefulasitis,withonlythedefaultfunctionalitythatFormshasbuiltforyou.Intheremainingsteps,youmakeadjustmentstoenhancetheusabilityoftheform.Thefirstthingyoudoiscreateanewcanvastodisplaymostofthedetailsaboutanemployee.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Inadditiontothecontentcanvas,whichtakesupallthespaceinthewindow,youcancreatethreeothertypesofcanvases:

    Stackedcanvas CandisplayinfrontofacontentcanvasandisusuallysmallerthanthecontentcanvasTabcanvas SpecializedtypeofstackedcanvascontainingmultipletabpagesToolbarcanvas Canvasthatdisplaysaboveortotheleftofthecontentcanvas,typicallyusedforbuttons

    YoudecidetocreateasecondcontentcanvasandmovesomeoftheitemsfromtheEmployeesblocktothatcanvas.Inaddition,youdefineonthatsecondcanvassomeitemsthataresynchronizedwiththeitemsthatappearonthemaincanvas.

    Tocreatethesecondcontentcanvas,movesomeoftheEmployeesblockitemstoit,andcreatesomesynchronizeditems,performthefollowingsteps:

    1. SelectthecanvasintheObjectNavigatorandclickCreate .

    2. ChangethenamesofbothcanvasesbyclickingthenameintheObjectNavigator,thenclickingagainand

    overtypingtheexistingname.CalltheoriginalcanvasMAIN_CVandthenewcanvasEMP_DETAILS_CV.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Note:AlternativelyyoucouldchangethenameinthePropertyPalette.

    3. OpentheMAIN_CVcanvasintheLayoutEditor.IntheEmployeesblock,controlclick(ordragthemouse)to

    selecttheEmail,Phone_Number,Hire_Date,Salary,andCommission_Pctitems.ChooseEdit|Cutfromthemenu.

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. SelecttheEMP_DETAILS_CVcanvasfromtheCanvaspopuplistatthetopleftoftheLayoutEditorandselectEMPLOYEESfromtheBlockpopuplist.ChooseEdit|Pastefromthemenu.Dragtheitemstoalocationneartheupperleftcornerofthecanvas.

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. Withallitemsstillselected,openthePropertyPaletteandchangethefollowingproperties:

    Property ValueNumberofItemsDisplayed 1PromptAttachmentEdge StartPromptAttachmentOffset 5

    Thendragtheitemstoarrangethemonthecanvas,leavingsomeroomatthetopforthesynchronizeditemsthatyoucreatenext.

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. Changethebackgroundcolorofthecanvas.ClickablankspotonthecanvassothatthePropertyPalette

    displaysthecanvasproperties.ChangetheBackgroundColorpropertytoacolorofyourchoosing.

    7. SelectMAIN_CVfromtheCanvaspopuplistoftheLayoutEditor.SelecttogethertheEmployee_Id,

    First_Name,andLast_Nameitems.Fromthemenu,chooseEdit|Copy.

  • 6/8/2015 CreatingaMasterDetailForm

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

    8. SelectEMP_DETAILS_CVfromtheCanvaspopuplistoftheLayoutEditor.Fromthemenu,chooseEdit|Paste.

  • 6/8/2015 CreatingaMasterDetailForm

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

  • 6/8/2015 CreatingaMasterDetailForm

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

    9. Changethepropertyvaluesasyoudidinstep55above,thenchangethenamesofeachoftheitemstoM_EMPLOYEE_ID,M_FIRST_NAME,andM_LAST_NAME(theMisjustanindicationthattheseitemsmirror,oraresynchronizedwith,otheritems).

    IntheSynchronizewithItempropertyforeachitem,selectfromthepoplisttheitemwithwhichthisitemshouldbesynchronized.Forexample,M_Employee_IdshouldbesynchronizedwithEmployee_Id.

    Changeotherindividualpropertiesasshown:

    Item Property Value Note:Ifyoufailtosettheseproperties,theformstillfunctions,butyoureceiveannoyingmessageswhenyouruntheformfromFormsBuilder.Ifyouwouldprefernottosettheseproperties,youcanignorethemessages.

    M_EMPLOYEE_IDandM_LAST_NAME

    Required No

    M_FIRST_NAMEandM_LAST_NAME

    DataLengthSemanticsMaximumLength

    Null0

    Dragtheitemstothetopofthecanvasandarrangethemnearthetop.

    10. OpentheMAIN_CVcanvasagain.ToensurethatchangestothelayoutoftheEmployeesblockarepreserved,

    clickitsFrame(thelinethatsurroundstheitemsintheEmployeesblock).InthePropertyPalettefortheFrame,changethepropertyUpdateLayoutfromAutomaticallytoManually.

  • 6/8/2015 CreatingaMasterDetailForm

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

    11. MovethescrollbarfromthefarrightoftheMAIN_CVcanvastoapositionjusttotherightoftheremainingitems,

    thenresizetheframewidthappropriately.

    12. ClickSave tosavetheform,thenclickRunForm totestit(besurethatyouhavestartedOC4Jsee

    Step1).

    Whentheformstartsrunning,clickExecuteQuery todisplaydataintheform.ClickNextBlock tonavigatetotheEmployeesblock.Youstillmusttabthroughtheitemstobeabletoseethemall,butatleastnow

  • 6/8/2015 CreatingaMasterDetailForm

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

    theemployeedetaildisplaysallinonewindow.Youmaynoticethatnavigationthroughtheitemsonthedetailpageisnotwhatyoumightexpectyouchangethenavigationinalaterstep.

    Note:Youcoulduseastackedcanvas,ratherthanacontentcanvas,todisplaytheemployeedetails.Ifyouhadalargernumberofitems,youcoulduseatabcanvastodisplaythem,arrangingtheitemsondifferenttabpages.

    13. ClickExitForm toexittheapplication,thenclosethebrowserwindow.

    Step6CreatingaNewWindow

    BacktoTopicList

    Becauseyouhavetwocontentcanvasesandonewindow,youcandisplayonlyonecontentcanvasatatime.BothcanvasesdisplayinWindow1thatFormsBuildercreatedbydefault.

    Ifyouwouldliketoenableuserstoviewbothcanvasesatonce,youcancreateanotherwindow.TocreateanewwindowanddisplaytheEMP_DETAILS_CVcanvasinit,performthefollowingsteps:

  • 6/8/2015 CreatingaMasterDetailForm

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

    1. SelectthewindowintheObjectNavigatorandclickCreate .

    2. ChangethenamesofbothwindowsbyclickingthenameintheObjectNavigator,thenclickingagainandovertypingtheexistingname.CalltheoriginalwindowMAIN_WINandthenewwindowEMP_DETAILS_WIN.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Note:AlternativelyyoucouldchangethenameinthePropertyPalette.

    3. InthePropertyPaletteforeachwindow,changeitsTitleproperty.Thischangesthetitlethatdisplaysineachwindowoftherunningform.

    ChangethetitleforMAIN_WINtoDepartmentsandEmployees.ChangethetitleforEMP_DETAILS_WINtoEmployeeDetails.

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. SelecttheEMP_DETAILS_CVcanvasintheObjectNavigator.InthePropertyPalette,changeitsWindow

    propertybyselectingEMP_DETAILS_WINfromthepopuplist.

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. IntheLayoutEditorfortheMAIN_CVcanvas,placeyourcursoratthepointwhereyouwantthenewwindowto

    bedisplayed,andmakenoteoftheXandYcoordinatesshownatthebottomoftheLayoutEditorwindow.Inthiscase,theXandYcoordinatesare210and120.

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. InthePropertyPalettefortheEMP_DETAILS_WINwindow,settheXPositionandYPositionpropertiestothe

    valuesoftheXandYcoordinatesinthepreviousstep.TheexampleshowssettingXPositionto210andYPositionto120.

  • 6/8/2015 CreatingaMasterDetailForm

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

    7. OpentheEMP_DETAILS_CVcanvasintheLayoutEditorandresizetheViewport(blackrectangle)sothatitis

    justlargeenoughtodisplayalltheitems.YoumayneedtomaximizetheLayoutEditorwindowtobeabletoseetheoriginallowerrightpointoftheviewport.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Note:Resizingtheviewportactuallyresizesthewindowinwhichthecanvasisdisplayed.ItisavisualwaytochangetheheightandwidthpropertiesofthewindowwithouttheneedtochangethemdirectlyinthePropertyPalette.

    8. ClickSave tosavetheform,thenclickRunForm totestit(besurethatyouhavestartedOC4JseeStep1).

    Whentheformstartsrunning,clickExecuteQuery todisplaydataintheform.ClickNextBlock tonavigatetotheEmployeesblock.Tabthroughtheitemssothattheseparatewindowisinvoked.

    Designsuggestion:Becauseyoucannowseethedetailsalongwiththemaincanvas,youmaydecidetoeliminatethesynchronizeditemsfromthedetailcanvas.

    Itmayalsobehelpfultodifferentiatethecurrentrowonthemaincanvasvisually,suchasbyspecifyingadifferentbackgroundcolorforthecurrentitem.Youcandothisby:

    Definingavisualattribute(seetheonlinehelptopicCreatingaNamedVisualAttribute)SettingapropertyoftheEmployeesblockcalledCurrentRecordVisualAttributegrouptothenameofthevisualattributethatyoudefined

    9. ClickExitForm toexittheapplication,thenclosethebrowserwindow.

    Step7BuildingaControlBlock

    BacktoTopicList

    Althoughmostdatablocksarebasedontables,views,orstoredprocedures,youcancreateblocksthatarenotrelatedtothedatabase.SuchblocksarereferredtoasControlBlocks.ControlBlockstypicallycontainbuttons,calculateditems,orother

  • 6/8/2015 CreatingaMasterDetailForm

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

    objectsthatpertaintotheformasawhole,ratherthanjustasingleblock.

    Tocreateacontrolblocktodisplaythesumofdepartmentsalaries,performthefollowingsteps:

    1. SelecttheEmployeesblockintheObjectNavigatorandclickCreate .

    2. SelecttheoptiontoBuildanewdatablockmanually,thenclickOK.

    3. InthePropertyPaletteforthenewblock,setNametoCONTROLandsetSingleRecordtoYes.TheSingle

    RecordpropertyisappropriateforaControlBlockbecauseitdoesnotcontainmultiplerecords.

  • 6/8/2015 CreatingaMasterDetailForm

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

    Note:SingleRecordmustbesettoYesforaControlBlockthatcontainsasummarycalculateditem.

    4. IntheLayoutEditor,opentheMAIN_CVcanvas.SelectCONTROLfromtheBlockpopuplist.

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. ClicktheDisplayItemtool ,thenclickinthecanvastotherightoftheManageritem.

    6. UsingthePropertyPalette,setthefollowingpropertiesonthenewitem:

    Property ValueName SAL_SUMDataType NumberMaximumLength 14FormatMask $9,999,999.00CalculationMode SummarySummaryFunction SumSummarizedBlock EMPLOYEESSummarizedItem SalaryHeight 14Prompt TotalSalariesPromptAttachmentEdge Top

  • 6/8/2015 CreatingaMasterDetailForm

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

    7. AsummarizedblockmusthaveitsQueryAllRecordsorPrecomputeSummariespropertysettoYessothatthesumincludesallrecords,notonlythosealreadyretrievedintotheblock.InthePropertyPalettefortheEmployeesblock,setoneofthesepropertiestoYes.

  • 6/8/2015 CreatingaMasterDetailForm

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

    8. ClickSave tosavetheform,thenclickRunForm totestit(besurethatyouhavestartedOC4Jsee

    Step1).

    Whentheformstartsrunning,clickExecuteQuery todisplaydataintheform.ClickNextRecord tonavigatetoadepartmentwithmorethanoneemployee.

    ClickNextBlock tonavigatetotheEmployeesblock.Tabthroughtheitemssothattheseparatewindowisinvoked.

    Whilethecursorisintheseparatewindow,clickNextRecord throughallexistingemployeerecordsandverifythatthetotaldepartmentsalariesfigureiscorrect.

  • 6/8/2015 CreatingaMasterDetailForm

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

    9. ClickExitForm toexittheapplication,thenclosethebrowserwindow.

    Step8ControllingNavigation

    BacktoTopicList

    Asyouweretestingtheform,dependingonhowyouarrangedtheitemsyoumayhavenoticedthatthecursordidnotmoveinthedesiredsequencewhenyoutabbedthroughtheitems.Inaddition,youmaypreferthatwhenyoutaboutofthelastiteminanEmployeesrecord,thatthecursorshouldmovetothenextrecord,andthatwhenyoutaboutofthelastiteminaDepartmentsrecord,thatthecursorshouldmovetotheEmployeesblock.Inthisstep,youchangethenavigationordersothatthesethingsareaccomplished.

    Tochangenavigationorder,performthefollowingsteps:

    1. Bydefault,navigationorderisdeterminedbythesequenceinwhichobjectsappearintheObjectNavigator.

    OpentheEMP_DETAILS_CVcanvasintheLayoutEditor.IntheObjectNavigator,dragtheitemsintheEmployeesblocktotheorderinwhichyouwantthenavigationtooccur.

    Forexample,whenitemsarearrangedonthecanvasasshownbelow,youwantthecursortomovetoHIRE_DATEwhenyoutaboutofPHONE_NUMBER.Tochangethesequence,youdragHIRE_DATEintheObjectNavigatortothepositionjustafterPHONE_NUMBER.

    IgnoretheitemsJOB_ID,MANAGER_ID,andDEPARTMENT_ID,becausethoseitemsarenotdisplayedonanycanvas,sonavigationtothoseitemsdoesnotoccur.

  • 6/8/2015 CreatingaMasterDetailForm

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

    2. Youcanalsouseblockpropertiestoaffectnavigationorder.

    InthePropertyPalettefortheDepartmentsblock,changetheNavigationStylepropertytoChangeDataBlock.

  • 6/8/2015 CreatingaMasterDetailForm

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

    3. InthePropertyPalettefortheEmployeesblock,changetheNavigationStylepropertytoChangeRecord.

    4. ClickSave tosavetheform,thenclickRunForm totestit(besurethatyouhavestartedOC4Jsee

  • 6/8/2015 CreatingaMasterDetailForm

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

    Step1).TestthatthenavigationorderisthesameaswhatyoudeterminedbymovingtheitemsintheObjectNavigator,thatthecursormovesintotheEmployeesblockwhenyoutaboutoftheDepartment_Nameitem,andthatthecursormovestothenextEmployeesrecordwhenyoutaboutofthelastitemintheEmployeesblock.

    ClickExitForm toexittheapplication,thenclosethebrowserwindow.

    5. Youcanalsoaffectnavigationwithitemproperties.

    Inpreparationforsomenewfunctionalitythatyouimplementwithcodeinalaterstep,changethefollowingitempropertiesintheEmployeesblock:

    Item Property Value

    EMPLOYEE_ID PreviousNavigationItem LAST_NAME

    LAST_NAME NextNavigationItem EMPLOYEE_ID

    Note:Whenviewingaqueriedrecord,thismakesitimpossibletonavigatetotheemployeedetailsshownontheEMP_DETAILS_CVcanvas.Youaddtheabilitytonavigatetotheseitemsinalaterstep.

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. ClickSave tosavetheform.

    Step9ModifyingtheLayout

    BacktoTopicList

    Whenyouattempttoinsertanewemployeerecord,youdiscoverthatyouhaveomittedarequireddatabasecolumn,JOB_ID,fromthelayout.YoudidincludeJOB_IDinthedatablockitselfifyouhadnot,youcouldusetheDataBlockWizardinreentrantmodetoaddtheJOB_IDtothedatablock.ToinvoketheDataBlockWizardinreentrantmode,youjustrightclicktheblockintheObjectNavigatorandchooseDataBlockWizardfromthecontextmenu.

    Sothatitisbepossibletousetheformtoinsertemployeerecords,youcouldusetheLayoutWizardinreentrantmodetoaddtheitemtothelayoutforthatrequireddatabasecolumn.However,usingtheLayoutWizardarrangestheitemsintheiroriginaltabularlayoutwithintheframeontheMAIN_CVcanvas,andthisisnotdesirableforthisapplication.Ifyouwanttotrythistoseetheeffect,savetheformfirstsothatyoucanreverttothesavedcopy,thenrightclicktheEmployeesframeontheMAIN_CVcanvasandselectLayoutWizardfromthecontextmenutoopentheLayoutWizardinreentrantmode.YoucantellthatyouareinreentrantmodebecausetherearetabsalongthetopoftheWizardandthereisanApplybuttonthatdoesnotexistunlesstheWizardisinreentrantmode.ThenontheDataBlocktab,moveJOB_IDtoDisplayedItemsandclickFinish.Afteryouexperimentwiththis,closetheformwithoutsavingit(selecttheHRformintheObjectNavigatorandclickDelete),thenreopenthesavedformtocontinue.

    InsteadofusingtheLayoutWizardinreentrantmodetomodifythelayout,inthisstepyousimplychangethepropertiesoftheJOB_IDitem.ToaddJOB_IDtotheEMP_DETAILS_CVcanvas,performthefollowingsteps:

    1. SelecttheJOB_IDitemintheObjectNavigatoranddisplayitsPropertyPalette.ChangeitsCanvasPropertytoEMP_DETAILS_CV,changeNumberofItemsDisplayedto1,andchangePromptAttachmentOffsetto5.

  • 6/8/2015 CreatingaMasterDetailForm

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

    2. OpentheLayoutEditorfortheEMP_DETAILS_CVcanvas.TheJOB_IDitemisdisplayedintheupperleft

    corner.Dragittothedesiredpositiononthecanvas.

  • 6/8/2015 CreatingaMasterDetailForm

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

    3. IntheObjectNavigator,dragtheJOB_IDitemtotheproperpositionforthedesirednavigationorder.

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. ClickSave tosavetheform,thenclickRunForm totestit(besurethatyouhavestartedOC4Jsee

    Step1).

    Beforequeryinganydata,attempttoinsertanewDepartmentsrecord.Enter99fortheDepartment_IdandTestfortheDepartment_Name.ClickSave .Therecordshouldbeinsertedwithouterror.

    5. ClickRemoveRecord todeletetherecordthatyoujustinserted,thenclickSave .Therecordshould

    bedeletedwithouterror.

  • 6/8/2015 CreatingaMasterDetailForm

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

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. ClickExecuteQuery .NavigatetotheEmployeesblockandclickInsertRecord .

    Enter999fortheEmployee_ID,andenteryourownfirstandlastname.ClickSave .

    Becausetherearesomerequireditemsthathavenovalues,youreceiveanerrorandFormsautomaticallynavigatestothefirstnullrequireditem.EnterIT_PROGfortheJob_Id,thenfillinanyvaluesyoudesirefortheotheritems.ThenclickSave .TherecordshouldbesavedsuccessfullynoticethattheTotalSalariesamountisrecalculatedautomatically.Youmaydeletethenewrecordifdesired.

    ClickExitForm toexittheapplication,thenclosethebrowserwindow.

    Step10AddingFunctionalitywithCode

    BacktoTopicList

    Nowyouhaveafullyfunctionalmasterdetailformthatenablesyoutoquery,insert,update,anddeleterecords.Theform

  • 6/8/2015 CreatingaMasterDetailForm

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

    evenperformscalculationsautomatically,andyouhavenotwrittenasinglelineofcodetoachievethisfunctionality.FormsBuildermakesiteasytodeclarativelydevelopacompleteapplication.

    However,youmaydesiretoaddfunctionalitybycodingPL/SQLprogramunitsandtriggersinyourform.Atriggerisablockofcodethatexecutesinresponsetoacertainaction,suchaswhentheuserclicksabutton.

    Inthisstep,youwritecodetoperformthefollowing:

    ExecuteaqueryautomaticallyPopulatenonbasetableitemswhenqueryingUselistsofvaluesforuserinputCreateabuttontodisplaydetailsAdjustnavigationprogrammaticallyCloseawindowprogrammatically

    ExecuteaQueryAutomatically

    BacktoList

    Itiscommonfortheusertowantdatatobedisplayedintheformwhenitfirstopens.Toexecuteaqueryautomaticallywhentheformstarts,performthefollowingsteps:

    1. IntheObjectNavigator,rightclicktheformlevelTriggersnode,thenselectSmartTriggers|WHENNEWFORMINSTANCEfromthecontextmenu.

  • 6/8/2015 CreatingaMasterDetailForm

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

    2. ThePL/SQLEditoropensupfortheformlevelWhenNewFormInstancetrigger.Enterthefollowingcode:

    DO_KEY('EXECUTE_QUERY')

    ThenclickCompile inthePL/SQLEditor.Amessageshowingthatthetriggeriscompileddisplaysinthelowerrightcorneroftheeditor.

    ClickSave .

    PopulateNonBaseTableItemsWhenQuerying

    BacktoList

    Onewaytolookuprelateddataanddisplayitautomaticallyinnonbasetableitemsistouseapostquerytrigger.Thistechniquerequiresaroundtriptothedatabaseforeachrowthatisretrievedbythequery,soitcanresultinslowerperformance.Foralargenumberofrecords,youmaywanttoconsiderbasingthetableonavieworonasetofstoredprocedures,whichmayprovidebetterperformance.

    Toautomaticallypopulatethenonbasetableitemswhenquerying,performthefollowingsteps:

    1. UndertheDepartmentsblockintheObjectNavigator,selecttheTriggersnode,thenclickCreate .

  • 6/8/2015 CreatingaMasterDetailForm

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

    2. TypepintheFindbox,thenselectPOSTQUERYfromthelist.ClickOK.

    3. ThePL/SQLEditoropensupfortheblocklevelPostQuerytriggerfortheDepartmentsblock.ThePostQuery

    triggerfiresforeveryrowthatisretrievedbyaqueryoftheDepartmentsblock.Enterthefollowingcode:

    SELECTCITY||','||STATE_PROVINCE||','

  • 6/8/2015 CreatingaMasterDetailForm

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

    ||COUNTRY_IDINTO:departments.locationFROMlocationsWHERE:departments.location_id=location_id

    SELECTFIRST_NAME||''||LAST_NAMEINTO:departments.managerFROMemployeesWHERE:departments.manager_id=employee_id

    ThenclickCompile inthePL/SQLEditor.Amessageshowingthatthetriggeriscompileddisplaysinthelowerrightcorneroftheeditor.

    ClickSave .

    UseListsofValuesforUserInput

    BacktoList

    AListofValues(LOV)canbeattachedtoanyinputitemtohelpuserstoenteraccuratedata.ThereislittlecodinginvolvedindefininganLOVotherthantypingintheSELECTstatementtouse.

    YoucoulduseLOVsforLocationandManager,thenpopulatethosenonbasetableitemsalongwiththeirassociatedbasetableitems,Location_IdandManager_Id.However,inthisexample,youuseanLOVtoenabletheusertoselectavalidJob_Idforanemployee.

    TodefineanLOVfortheJob_Iditem,performthefollowingsteps:

    1. ClicktheLOVsnodeintheObjectNavigator,thenclickCreate .

  • 6/8/2015 CreatingaMasterDetailForm

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

    2. LeavetheUsetheLOVWizardoptionselectedandclickOK.

    3. OnthefirstpageoftheLOVWizard,clickNexttobasetheLOVonanewrecordgroupbasedonaquery.

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. FortheSQLQueryStatement,enterthefollowing:

    SELECTjob_titleTITLE,job_idIDFROMjobsORDERBYjob_title

    Donotendthestatementwithasemicolon.

    Ifyouwanttoensurethatthestatementissyntacticallycorrect,clickCheckSyntax.YoushouldreceiveamessageaffirmingthecorrectnessofthestatementclickOKtodismissthismessage,thenintheLOVWizard,clickNext.

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. IntheLOVyouwanttodisplaytheJob_Titletotheuser,becausethiscontainsinformationthatismeaningfulto

    theuser.YoudecidetoalsodisplaytheJob_Id.Clickthedoublerightarrowbutton tomovebothrecordgroupcolumnstotheLOV,thenclickNext.

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. WhatyouaretryingtoaccomplishistopopulatetheJob_IditemintheEmployeesblockwiththeIDselected

    fromthequery.

    ClicktheReturnvaluecolumnfortheIDcolumn,thenclickLookupreturnitem....IntheItemsandParameterslist,select:EMPLOYEES.JOB_ID,thenclickOK.

    CheckAutomaticallysizecolumns,thenclickNext.

  • 6/8/2015 CreatingaMasterDetailForm

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

    7. EnterJobsfortheLOVTitle,250fortheWidth,and300fortheHeight.ClickNext.

  • 6/8/2015 CreatingaMasterDetailForm

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

    8. ClickNexttoacceptthedefaultsofretrieving20rowsatatimeandrefreshingtherecordgroupbefore

    displayingtheLOV.

  • 6/8/2015 CreatingaMasterDetailForm

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

    9. YouwanttheLOVtobeavailablefromtheJob_IDitemintheEmployeesblock.Clicktherightarrowbutton

    tomoveEMPLOYEES.JOB_IDfromReturnItemstoAssignedItems,thenclickNext,andonthefinalscreen,clickFinish.

  • 6/8/2015 CreatingaMasterDetailForm

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

    ClickSave .

    CreateaButtontoDisplayDetails

    BacktoList

    BecausethereisnownoeasywaytonavigatetoitemsontheEMP_DETAILS_CVcanvas,youcreateabuttonenablinguserstodoso.

    Inmostcases,youwouldcreatebuttonsintheControlblock.However,thebuttonneedstoknowwhichrecordintheEmployeesblocktodisplaydetailsfor,andtheeasiestwaytodothis(thereareotherways)istoplacethebuttonintheEmployeesblock.

    Formostbuttons,yousettheMouseNavigatepropertytoNo.Inthiscase,however,youwanttoselectanemployeerecordanddisplayitsdetailswithoneclick,soyouleaveMouseNavigatesettoitsdefaultvalue,whichisYes.

    Tocreateabuttontodisplayemployeedetails,performthefollowingsteps:

    1. OpentheLayoutEditorfortheMAIN_CVcanvas.EnlargetheEmployeesframetotherightbyselectingitanddraggingitsresizehandle.Movethescrollbartotherightsideoftheframe.

  • 6/8/2015 CreatingaMasterDetailForm

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

    2. SelectEMPLOYEESfromtheblocklistintheLayoutEditor.ClicktheButtontoolintheLayoutEditor,thenclick

    intheareabetweenLast_Nameandthescrollbar.

  • 6/8/2015 CreatingaMasterDetailForm

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

    3. OpenthePropertyPaletteforthebuttonandsetthefollowingproperties:

    Property ValueName DETAILS_BTNLabel DetailsWidth 50Height 14

  • 6/8/2015 CreatingaMasterDetailForm

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

    4. IntheObjectNavigator,dragthebuttontoapositionjustafterLast_Name.

  • 6/8/2015 CreatingaMasterDetailForm

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

    5. RightclicktheDETAILS_BTNbutton,andfromthecontextmenuchooseSmartTriggers|WHENBUTTON

    PRESSED.

  • 6/8/2015 CreatingaMasterDetailForm

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

    6. InthePL/SQLEditor,enterthefollowingcode:

    GO_ITEM('job_id')

    ClickCompile .

  • 6/8/2015 CreatingaMasterDetailForm

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

    ClickSave .

    AdjustNavigationProgrammatically

    BacktoList

    YoupreviouslysettheNavigationStylepropertyoftheEmployeesblocktoChangeRecord,whichmeansthatwhentheusertabsoutofthelastitemintheblock,thecursorgoestothefirstiteminthenextrecord.However,becauseLast_Nameisnotthelastitemintheblock,tabbingoutofitsimplynavigatestotheEmployee_Idofthesamerecord.

    Toadjustnavigationsothattabbingfromtheemployee'slastnamenavigatestothenextrecord,performthefollowingsteps:

    1. IntheObjectNavigator,expandtheLast_NamenodeundertheEmployeesblock,andselecttheTriggersnode.ClickCreate .

    2. IntheTriggerswindow,scrolldownandselectKEYNEXTITEM,thenclickOK.

  • 6/8/2015 CreatingaMasterDetailForm

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

    3. InthePL/SQLEditor,enterthefollowingcode,thenclickCompile :

    do_key('next_record')

    ClickSave .

    CloseaWindowProgrammatically

    BacktoList

    WhentheuserclickstheXonaFormswindowtocloseit,bydefaultnothinghappens.Ifyouwanttheusertobeabletoclosethewindow,youmustcodetheactiontotake.

    ToclosetheEMP_DETAILS_WINwindowwhentheuserclickstheX,performthefollowingsteps:

  • 6/8/2015 CreatingaMasterDetailForm

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

    1. SelecttheTriggersnodeundertheHRform,clickCreate ,andchooseWHENWINDOWCLOSEDfromthetriggerlist,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')THENGO_ITEM('employee_id')HIDE_WINDOW('emp_details_win')ENDIF

  • 6/8/2015 CreatingaMasterDetailForm

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

    ClickSave .

    3. ClickRunForm totestit(besurethatyouhavestartedOC4JseeStep1).

    Demonstratethat:

    Theformdisplaysthedata(executesthequery)automatically.TheLocationandManageritemsarepopulatedautomatically.WhennavigatingintheEmployeesblockontheMaincanvas,tabbingoutofLast_Namenavigatestothenextemployeerecord.EmployeedetailsdisplaywhenyouclickDetailsintheEmployeesblock.IntheJob_IditemyoucandisplayandselectfromanLOVwhenyoupressCtrl+L,andtheJob_Iditemispopulatedwiththejobthatyouselect.Youcanclosethedetailwindow.

    ClickExitForm toexittheapplication,thenclosethebrowserwindow.

    Summary

    BacktoTopicList

    ThisexerciseshowedyouhoweasyitistocreateamasterdetailformusingtheDataBlockandLayoutWizardsinFormsBuilder.Youalsomanuallycreatedacontrolblockonwhichyouplacedanitemtoautomaticallycalculatethesumofsalariesforadepartment.

    Youenhancedadatablockwithnonbasetableitemstodisplaydatafromrelatedtables,andyoumovedsomeitemstoanewcanvastodisplayinaseparatewindow.Youadjustednavigationandaddedanotherbasetableitemtothelayout.ThisfullyfunctionalmasterdetailformwasachievedusingonlythevisualanddeclarativeIDEofFormsBuilder.

    Youthenaddedcodetoexecuteaqueryautomatically,populatethenonbasetableitems,definealistofvaluestoaiduserinput,createabuttontodisplayemployeedetails,furtherrefinenavigationprogrammatically,andprogrammaticallyclosethe

  • 6/8/2015 CreatingaMasterDetailForm

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

    separatewindow.

    ThisbriefoverviewonlyscratchesthesurfaceofwhatyoucanaccomplishwithFormsBuilder.Formoreinformation,seeRelatedTopicsbelow.

    Relatedtopics

    OracleEducationcourses:OracleFormsDeveloper10g:MovetotheWeb

    OracleEducationcourses:OracleFormsDeveloper10g:BuildInternetApplications

    OTN:FormsProductspage

    Moveyourmouseoverthisicontohideallscreenshots