Tải bản đầy đủ - 0 (trang)
Chapter 13. Developing and Testing JSPs in WSAD

Chapter 13. Developing and Testing JSPs in WSAD

Tải bản đầy đủ - 0trang

basedapplication.



Figure13.1.Architecturalroadmap.



13.1AnotherLookatMVC

BeforejumpingtoofarintothediscussionofdevelopmenttoolsforJSP,

weshouldrevisitthedeveloperrolesthatmayplayapartinthe

developmentandmaintenanceofJSPs.ManyearlyJSPdevelopers

wereJavaprogrammerswhoneededawaytopurgetheirservletsof

stringliteralsrepresentingHTMLtext.Forthem,anyscriptingtoolortext

editorthatpermitsdirectlyeditingtheHTML/JSPtagsissufficient.

WhentheJavaprogrammerswithinanorganizationbuildJSPs,the

developmentprocesstypicallyobservedhasthestaticcontentofthe

JSPsdevelopedbytheWebpagedevelopers.Thesepages,developed

tohaveconsistentlookandfeelwiththerestoftheWebsite,arethen

handedofftotheJavadeveloperstoaddinthescriptingcode

responsibleforprovidingthedynamiccontent.ThefinalJSPsareusually

returnedtotheWebpagedevelopmentteamformaintenance,underthe

assumptionthattheaddedscriptingcodewillrarely,ifever,needto

change.

Ingeneral,theWebpagedevelopmentteamonlymodifiesthestatic

HTMLportionsoftheJSPsourceasnecessaryinordertoaccountfor

newimages,links,textupdates,andsimilarvisualupdates.

TheMVCprogrammingstyle,particularlythewrappingofdynamic

contentinoneormoreJavaBeans,providestheopportunityfora

differentdevelopmentmodel.WhenpagedevelopersbuildJSPpages,

themostburdensometaskisplacingdynamiccontentwithinthepage.

ThisdifficultystemsfromthelackofaccessibilitytotheJava(JSP)

syntax.



13.2JavaBeans,Introspection,andContracts

ThekeyproblemofbuildingJSPpagesinanMVCenvironmentis

communication.Whenateamisdividedintoasetofindividualsthat

developWebpagesandasecondsetofindividualsthatareserver-side

Javadevelopers,lackofcommunicationcancreatechallenges.

Webdevelopersareawareofwhatcontentshouldappearonthepage.

Theymustcommunicatetotheserver-sidedevelopersthatcertain

dynamiccontentshouldbedisplayedonthatpage.Thisdynamiccontent

isgenerallydatathatresultsfromaclientrequest(whethersuccessfulor

unsuccessful).Itisalsopossiblefortheserver-sidedeveloperto

communicatetotheWebdeveloperwhatdynamiccontentisavailablefor

displayatagivenpointbasedontheinformationthathasbeencollected

fromtheuserandretrievedfromtheserver.

Formalizingthepackagingofthedynamiccontentrepresentsthecontract

betweentheJSPdeveloperandthebeanproviders.Definingoneor

moretypesthatexposethedynamiccontentaspropertiesspecifiesmost

ofthiscontract.ThesetypesareimplementedasJavaBeans.JavaBeans

havetheadvantageofbeingverytoolfriendly.Itisveryeasyforatoolto

introspectonaJavaBeanclass(and/oranaccompanyingBeanInfo

class)andpresenttothedevelopertheavailableproperties,events,and

methods.ForourDisplayPageJSPs,theseJavaBeansonlyneedto

deliverdynamiccontentasbeanproperties.

TherestofthecontractinvolvesthelocationoftheJavaBeansat

runtime.Inotherwords,whatinformationmustbesuppliedinthe

useBeanaction,tomakeitpossibletolocatetheJavaBeans(i.e.,inwhat

scopeandunderwhatIDwillthebeanbefound).

AtypicalJSPpagedevelopmenttoolfeaturepermitsbrowsingasetof

JavaBeanstoselectapropertyfordisplayonthepage.Complexities

ariseindealingwithindexedpropertiesprimarilywithspecifyingthe

contextforindexing,andnestedproperties.Nestedpropertiesarisewhen

thestructureofthedynamicdataiscomplex.Forexample,considerour



TimeSheetobject.Thisobjectrepresentsacollectionof

TimeSheetEntries.ATimeSheetEntrycontainspropertiesfordateand

project,neitherofwhichareprimitivedata.Ifonewantstodisplaythe

projectnameforaparticularTimeSheetEntry,theJSPexpressionwould

looklike:

<%=TimeSheet.getEntry(index).getProject().getName()%>



Thiscouldalsobespecifiedbywalkingthebeansandtheirproperties

andselectingtheleafpropertyname(TimeSheet,entry(index),project,

name).ForatooltofacilitatewalkingnestedJavaBeanproperties,each

propertymustbeavailableinanontypehidingmanner.Forinstance,in

thepreviousscenario,itispossibletogetatthecollectionof

TimeSheetEntriesviathemethodgetEntries()ontheTimeSheet

object.ThisreturnsavectorofTimeSheetEntryobjects.

Avector,however,hidesthetypeinformationofitscontents.All

accessorstothecontentsofthevectoronlyguaranteethattheyreturnan

instanceoftheObjectclass.Atoolwillnotbeabletoexposethe

propertiesoftheactualJavatypestoredinthecollection,onlythelimited

propertiesofjava.lang.Object.Bysupplyingtheindexedproperty

entryintheTimeSheetbean,itispossibletoperformrecursive

introspectionandmaketheprojectnamevisibletoadeveloper.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 13. Developing and Testing JSPs in WSAD

Tải bản đầy đủ ngay(0 tr)

×