英文文献 科技类 原文及翻译 65文档格式.docx
《英文文献 科技类 原文及翻译 65文档格式.docx》由会员分享,可在线阅读,更多相关《英文文献 科技类 原文及翻译 65文档格式.docx(14页珍藏版)》请在冰豆网上搜索。
DbFormsbuildsontopofJavaServlets2.2andJavaServerPages1.1technologiesbySunMicrosystems.ItmakesextensiveuseoftheJSPTagLibraryextensionintroducedintheJSP1.1specification.
Theproject'
shomepageislocatedathttp:
//www.dbforms.organdcontainsacompleteusermanual,severaltechnicalarticles,sourceandbinarydistributions,onlineexamples,aCVS,mailinglists,andlotsofotherinformationrelatedtoDbForms.
DbFormsimplementstheconceptsoftheModel-View-Controller(MVC)designpattern.(SeeDesignPatterns:
ElementsofReusableObject-OrientedSoftware,ErichGamma,RichardHelm,RalphJohnson,andJohnVlissides,AddisonWesley,October1994.)YoudonotneedtoprovideanyController-relatedcode;
justfocusondefiningtheModelandcreatingtheJSPviewcomponentsoftheapplication(mainlyusingDbFormscustomtags).
ThefollowingdiscusseshowModel,ViewandControllerinteractinDbForms.
TheModel:
DatabaseObjectsDescribedbyDatabaseMetadata
TheuseofDbFormsistoperformoperationsondatabases.ThedatabasetablesaccessedbyaDbFormsapplicationmustbedeclaredinaXMLconfigurationfile(usuallystoredasWEB-INF/dbforms-config.xml),whichisparsedandevaluatedatWeb-applicationstartuptime.
AsshowninListing1,everytable(orview)tobeaccessedbyDbFormshastobedeclaredinsideofa<
table>
element.Allrelevanttablefieldsneedtobedeclaredinsideofa<
field>
elementnestedwithinitsrespective<
element.
ThereexistsatoolforgeneratingthisXMLdataautomatically.Thetoolreadsdatabasemetadataofaspecifieddatabaseandconstructsaconfigurationfile,asshowninListing1.TheController:
Parsing,Dispatching,andExecutingEvents
Aspointedoutabove,youdonotneedtoprovideanyController-relatedcodewhentheControllerisatrueinfrastructuralcomponent.However,it'
susefulifyouhaveanideaofwhat'
sgoingoninsidetheController.Thefollowinglinesprovidethatinformation.
TheControllerincludesseveralcomponents:
ControllerServlet:
thisservletisthesinglepointofentryforallincomingHTTPrequestsfromclients.
EventEngine:
anassistanttotheControllerServlet,itfocusesonfilteringHTTPrequestsforWebEventsandinstantiatesthem.
WebEventObjects:
allObjectsderivedfromtheabstractsuper-classWebEventhavetheabilitytoinitializethemselvesbyreadingagivenHTTPrequest.Theseeventsgetexecuted,eitherdirectlybytheControllerorbytheView.
Thefollowingdescriptionoftheexecutionofatypicaluseractionshouldgiveyouabetterpictureofwhatthecontrollerdoesandhowitinteractswiththeothercomponents:
1.Userpressesthebutton"
deleterow"
onhis/herDbFormsapplication.
2.ClientbrowsersubmitsdataviaHTTP-POSTtotheController-servlet.
3.TheControllerServletdelegatestheincomingrequesttotheEventEngine,whichdeterminesthemainevent(theuserexplicitlytriggeredtheeventbyclickingabutton).However,theremayoccurimplicitevents,too--i.e.,automaticupdatingofallchangedinputfieldsofalldatarows.
4.TheEventEnginecomponentparsesthatrequestanddeterminesthekindofactiontheuserwantstobeexecuted.
5.ItthencreatestheappropriateWebEvent(inourcase,aDeleteEvent)anddelegatestherequestObjecttothisnewly-createdWebEvent,whichfinalizesitsowninitialization.Afterthat,theEventEnginereturnstherecently-createdand-initializedeventbacktotheControllerServlet.
6.TheControllerServlettellstheeventtoexecuteitsbuilt-inoperation,ifitisaDatabaseEvent.Otherevents(NavigationEvent,etc.)aredelegatedtotheappropriateViewcomponent.
7.TheControllerServletinvokesEventEngineagaintocheckifthereareadditional(implicit)eventstobeexecuted.Ifso,theappropriatedWebEventObjectsarecreatedandexecutedinthesamemannerasthemaineventdescribedabove.
8.TheControllerServletdeterminestheViewcomponenttowhichtherequestshouldbeforwarded.Iffound,theControllerServletinvokesthecomponentandforwardstherequest.
9.IftheViewcomponentisaJSPpagecontainingDbFormstags,thosetagswillsearchfornavigationeventstobeexecuted,andwillfinallygeneratetheresponsefortheuser.
10.Theresponseisrenderedbytheuser'
sWebbrowser.
TheView:
JSPTemplatesProvidedbytheApplicationDeveloper
TheViewportionofaDbFormsapplicationisgenerallyconstructedusingJSPtechnology.JSPfilesmaycontainstaticHTMLelements,aswellasdynamicelementscontainingJavacode(definitions,statements,expressions).FormoreinformationaboutJSP,pleaseseeSun'
sJSPpage.
Withrelease1.1oftheJSPAPI,apowerfulfacilitycalledJSPtaglibrarieswasadded.Withthesecustomtags,youcanencapsulateevenmostsophisticatedJavacodeintolightweightJSPtags.
DbFormsmakesuseofthegreatpotentialofJSPtaglibraries.Itcontainsanextensivecustomtagslibraryforrenderingandmanipulatingdatabasedata.
TheStructureofaDbFormsView
Figure1givesaconceptualoverviewofthemaincomponentsofatypicalDbFormsview.
TheBasicConceptsofForms
EachDbForms-viewJSPmayhaveoneormoreroottagsofthetypeform.Everyformtaghastocontainexactlyoneheadertag,exactlyonebodytag,andexactlyonefootertag,inexactlythatorder.
Eachofthosetagsmaycontainsub-elementslikedatafields,inputfields,actionbuttons,and--ofcourse--plainHTMLtextandJSPcode.
headerandfootertagsarecommonlyusedfortitlesofpages,labellingtables,placingactionandnavigationbuttons,inputfieldstoenternewdata,etc.headerandfootertagsgetevaluatedonlyonce.
Thebodytagisusedforshowingdatarowscomingfromthedatabase,andforprovidingtheuserwiththefunctionalitytoeditthatdata.Howmanytimesthebodytaganditssub-elementsgetrendereddependsonthevalueofthemaxRowsattributeoftheformelement(andofcourse,onthenumberofdatasetsactuallyfetchedfromthedatabase).
maxRows=n--bodygetsexecutedntimesatmaximum(withninN)
maxRows="
*"
--bodygetsexecutedforeveryrowinthetable("
endless"
form)
NestedForms
Everyformmaycontainoneormorenestedsub-formsinsideitsbodyelement.
The"
orders"
formisnestedwithinthebodyelementofthe"
customer"
form,asshowninFigure2.Theuserwillseeonecustomerperpage(becausemaxRowsissetto"
1"
)andalltheorders(becausemaxRows="
)thecustomerhastaken.Theusermaynavigatethroughthelistofcustomersbyclickingthenavigationbuttons.
OK,Let'
sSeeSomeCode!
Asstatedbefore,JSPviewsaretheonlypartsofaDbFormsapplicationadeveloperusuallyneedstoputhis/herhandson.DbFormsprovidesanextensivecustomtaglibrarywhichmakesthisaneasytask,sothatitcanbeperformedevenbynon-programmers.
Aswewillseelater,muchofthiscodecanbegeneratedautomaticallybytoolsincludedinDbForms.However,itisusefultounderstandthebasicsofDbFormsviews,evenifmuchoftheworkcanbedoneautomatically.
ThefollowingtwosectionswillshowasimpleandamoreadvancedexampleofaDbFormsview.BothexamplescanbethoughtasbeingpartsofalittleCRMapplicationofa(virtual)agency.
ASimpleExample
Description:
ThisJSPview(service.jsp)enablestheuser(s)toadministertheservicestheagencyprovidestoitscustomers.Theuser(anemployeeoftheagencyorcallcenteragent)shouldgetalistofalltheexistingservices,alongwithtextfieldsandbuttonstoupdateanddeletedata.Finally,anemptyinputmaskforinsertingnewservicesisneeded.
WehavesetmaxRowsto"
whichhastheeffectthatallrowswillbeshownatonce.Ifthereexisthundredsofservices,wewouldliketosetmaxRowsto"
10,"
"
20,"
oranotherlimitednumber,andwewouldinstantiatenavigationbuttonsforscrollingbetweenthepages.Wewillusethatpatternlater.
Theerrorstagshowsalistoferrors,ifanyoccurred(i.e.duplicatekeyerror,etc.).
TheupdateButtonanddeleteButtontagsareplacedinthebodyandthereforerenderedforeachrow.
AnExampleofNestedForms
Thefollowingpage(customer_order.jsp)givesyouthefunctionalitytomanagetheincomingordersofacustomer.Youareabletoeditbothordersofacustomerandthecustomerdataitself.Furthermore,youdonotneedtostrugglewithplainserviceIDs,butwillbeabletoconvenientlyselecttheservicesfromaselectboxbyname.
Withthispage,wehavedemonstratedanothercoupleofm