GerdWagnerandMirceaDiaconescu WebApplicationswithJavascriptorJava DeGruyterGraduate Also of interest WebApplicationswithJavascriptorJava Volume:ConstraintValidation,Enumerations,SpecialDatatypes G.Wagner,M.Diaconescu, ISBN----,e-ISBN----, e-ISBN(EPUB)---- ProgramminginC X.Zhou,Q.Miao,L.Feng, Volume:BasicDataStructuresandProgramStatements ISBN----,e-ISBN----, e-ISBN(EPUB)---- Volume:CompositeDataStructuresandModularization ISBN----,e-ISBN----, e-ISBN(EPUB)---- AnalogandHybridComputerProgramming B.Ulmann, ISBN----,e-ISBN----, e-ISBN(EPUB)---- ElementarySynchronousProgramming inC++andJavaviaalgorithms A.S.Janfada, ISBN----,e-ISBN----, e-ISBN(EPUB)---- MachineLearningandVisualPerception B.Zhang, ISBN----,e-ISBN----, e-ISBN(EPUB)---- Gerd Wagner and Mircea Diaconescu Web Applications with Javascript or Java Volume 2: Associations and Class Hierarchies Authors Prof.Dr.GerdWagner BTUCottbus-Senftenberg FachgebietInternettechnologie Konrad-Wachsmann-Allee5 03046Cottbus [email protected] MirceaDiaconescu [email protected] Thisbook,alongwithanyassociatedsourcecode,islicensedunderTheCodeProjectOpen License(CPOL),seehttp://www.codeproject.com/info/cpol10.aspx,implyingthattheassociated codeisprovided“as-is”,canbemodifiedtocreatederivativeworks,canberedistributed,andcan beusedincommercialapplications,butthebookmustnotbedistributedorrepublishedwithout thepublisher’sconsent. ISBN978-3-11-050024-0 e-ISBN(PDF)978-3-11-050032-5 e-ISBN(EPUB)978-3-11-049756-4 LibraryofCongressControlNumber:2020948051 BibliographicinformationpublishedbytheDeutscheNationalbibliothek TheDeutscheNationalbibliothekliststhispublicationintheDeutscheNationalbibliografie; detailedbibliographicdataareavailableontheInternetathttp://dnb.dnb.de. ©2021WalterdeGruyterGmbH,Berlin/Boston Coverimage:monsitj/iStock/thinkstock Typesetting:IntegraSoftwareServicesPvt.Ltd. Printingandbinding:CPIbooksGmbH,Leck www.degruyter.com ToOurFamilies. Foreword Thistwo-volumebookshowshowtodesignandimplementwebapplicationswitha model-based engineering approach, using the two most relevant technology plat- forms for web development: JavaScript and Java. Web apps are designed with the helpofinformationmodelsintheformofUMLclassdiagramsandimplementedas: 1. JavaScript front-end apps, using one of the two local storage technologies of- feredbywebbrowsers; 2. Javaback-endapps,usingJavaServerFaces(JSF)asthe user interface technol- ogy,theJavaPersistenceAPI(JPA)forobject-to-storagemapping,andaMySQL/ MariaDBdatabasemanagementsystem. The focus of the book are general concepts and techniques concerning the funda- mentalinformationmanagementissuesof 1. integrityconstraintsanddatavalidation, 2. enumerationsandenumerationattributes 3. unidirectionalandbidirectionalassociationsbetweenobjecttypes, 4. subtypingandinheritanceinclasshierarchies. ThefirsttwoissuesofthislistarediscussedinVolume1ofthebook,whilethelast twoissuesarediscussedinVolume2. WeassumethatthereaderisalreadyfamiliarwithHTMLandwithatleastone object-oriented programming language, such as C++, Java, PHP, Python or C#. In addition, we assumethat thereader has somefamiliaritywithCSS and JavaScript, andisinterestedtolearnmoreaboutprogrammingwithJavaScriptorJava. Thebookcanbeused 1. in web development courses for students of Computer Science or Information Systemsandrelateddisciplines; 2. byJavaScriptdevelopersforlearningJava; 3. byJavadevelopersforlearningJavaScript; 4. byJavaScriptandJava(andPHP/Python/C#etc.)developersforlearning – object-oriented(OO)programmingwithJavaScriptorJava, – howtoimplementbasicinformationmanagementconceptsandbuildcom- pletewebappswithplainJavaScriptorJava. The book comes with the complete source code of six example apps that you can runordownloadfromourwebserver. https://doi.org/10.1515/9783110500325-202 Contents Foreword VII ListofFigures XIII ListofTables XV Part I:Associations 1 ReferencePropertiesandUnidirectionalAssociations 3 1.1 ReferencesandReferenceProperties 4 1.2 ReferentialIntegrity 6 1.3 ModelingReferencePropertiesasUnidirectionalAssociations 6 1.4 RepresentingUnidirectionalAssociationsasReference Properties 8 1.5 AddingDirectionalitytoaNon-DirectedAssociation 9 1.6 OurRunningExample 10 1.7 EliminatingUnidirectionalAssociations 11 1.8 RenderingReferencePropertiesintheUserInterface 15 1.9 CollectionTypesforMulti-ValuedReferenceProperties 15 1.10 QuizQuestions 16 2 ImplementingUnidirectionalFunctionalAssociationswithPlainJS 19 2.1 NewJavaScriptElements 19 2.2 ImplementingSingle-ValuedReferenceProperties 22 2.3 MakeaJSClassModel 24 2.4 NewIssues 26 2.5 CodetheModel 26 2.6 CodetheViewandController 33 2.7 QuizQuestions 36 3 ImplementingUnidirectionalNon-FunctionalAssociationswithPlain JS 38 3.1 ImplementingMulti-ValuedReferenceProperties 38 3.2 MakeaJSClassModel 39 3.3 NewIssues 40 3.4 CodetheModel 41 3.5 CodetheView 45 3.6 HowtoRuntheAppandGettheCode 51 3.7 PointsofAttention 52 X Contents 4 ImplementingUnidirectionalFunctionalAssociationswithJavaEE 53 4.1 ImplementingSingle-ValuedReferencePropertiesinJava 53 4.2 MakeaJavaEntityClassModel 54 4.3 NewIssues 55 4.4 WritetheModelCode 55 4.5 TheViewandControllerLayers 59 5 UnidirectionalNon-FunctionalAssociationswithJavaEE 67 5.1 ImplementingMulti-ValuedReferencePropertiesinJava 67 5.2 MakeaJavaEntityClassModel 68 5.3 NewIssues 69 5.4 WritetheModelCode 69 5.5 WritetheUserInterfaceCode 74 5.6 RuntheAppandGettheCode 76 5.7 SetsVersusOrderedSetsastheValuesofReference Properties 77 6 UnidirectionalAssociationsPracticeProjects 79 6.1 AssignaDirectorandActorstoaMovie 79 6.2 AssignCitiesandaCapitaltoaCountry,andMemberstoan Organization 80 7 BidirectionalAssociations 83 7.1 InverseReferenceProperties 83 7.2 MakinganOOClassModel 86 8 ImplementingBidirectionalAssociationswithPlainJS 91 8.1 MakeaJavaScriptClassModel 91 8.2 WritetheModelCode 92 8.3 ExploitInverseReferencePropertiesintheUserInterface 98 9 ImplementingBidirectionalAssociationswithJavaEE 100 9.1 MakeaJavaEntityClassModel 100 9.2 WritetheModelCode 102 9.3 ExploitingDerivedInverseReferencePropertiesintheUser Interface 110 9.4 RuntheAppandGettheCode 112 10 SpecialTopicsonAssociations 113 10.1 Part-WholeAssociations 113 10.2 AssociationClasses 116