SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

MVC in XPages
Model – View – Controller

M
C

V

A presentation for DanNotes
by John Dalsgaard
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Me
●

●

●
●

●
●

Worked with Notes since 1995
version 4.5
Java since Notes 5.0.7 (awfull Java
implementation – version 1.1!!!)
Large web-apps. (40.000+ users)
Object Oriented approach since 1999 (yes,
in LotusScript...)
Now: XPages & mobile apps....
Certified Principal/advanced administrator
and developer – all versions 4.6 → 8.5
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Agenda
●
●

Demo: What is this all about?
What is MVC
●
●
●

●
●

●

Data model: Data bean & DAO
Service layer: CRUD/Facade
View layer: View bean

Why would you want to use MVC
What to do in Domino
● Data structure
● Challenges...
A word about the Demo app.
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Demo
●
●
●
●

●

Simple example
Isolate data access (DAO + interface)
Validation in model (service layer)
Binding to Java beans through Expression
Language
Separate Model from View → Easy to add
new ”view” component
–
–

XPage
JSON WebService
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Demo – Data model
Person
Key
Name
Address
Zip
City
Email
YearBorn

1
n

Car

Key
PersonKey
Brand
Model
Colour
Convertible
Doors
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Agenda
●
●

Demo: What is this all about?
What is MVC
●
●
●

●
●

●

Data model: Data bean & DAO
Service layer: CRUD/Facade
View layer: View bean

Why would you want to use MVC
What to do in Domino
● Data structure
● Challenges...
A word about the Demo app.
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

What is MVC
●

A ”design pattern”
–

●

Very good practice for the task at hand

Separation of the tasks:
–
–
–

Model: Business rules, data model and data
manipulation
Viewer: Presentation of data
Controller: Flow in application
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

MVC - Model
●

Java objects that implement:
–

Data model
●
●

Contain data
Manipulate data from the database
–
–

–

Specific database implementation
CRUD (Create, Read, Update, Delete)

Service layer
●

Implement business rules
–
–

Validation
Combine data (e.g. number of years employed based
on hire date)
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

The MODEL
<<PersonDAO>>

Service layer

PersonCRUDFacade

implements

uses

Data model

DominoPersonDAO
encapsulates

Domino
DB

creates &
uses for DB
operations

obtains
updates

Person
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Data model
●

●

Is the only layer that knows the physical
details of data access (documents, views, etc.)
Consists of:
–

Data bean
●

–

all fields – with getter/setters – no logic

DAO (Data Access Objects)
●

Interface used by service layer
–

●

Defines all methods/operations

Implementation of interface
–
–

All handling of underlying database (e.g. recycle...)
Implements necessary base functions for CRUD
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Service layer
●

This is where the business logic of the
application lives
–
–
–
–

●

Workflows
Validations
Searches
Etc.

Connects to the DAO implementation through
its interface
–

Not relying on the implementation and the
underlying database ”dialect” (e.g. Domino)
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Service layer
●

Do not duplicate Domino ”techniques” from
the old days
–
–

Eg. Invoice with invoice lines
We have seen the pattern: line_1, line_2,
line_3 in traditional Notes applicatctions
●

–

Create two data objects and (DAO's etc.)
●
●

–

Fixed number of ”relations”
Invoice
InvoiceLine

Hide implementation details from the service
layer
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

MVC - View
●

Java objects for presentation that
–
–
–
–

Are used by the XPage
Often one-to-one between XPages and view
Beans
XPage talk to the view Bean – and never to the
underlying database (it doesn't know it exists!)
Typically defined to the XPages via facesconfig.xml
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

The VIEW
XPage

XPage

references

references

PersonViewBean

PersonEditBean

uses

uses

Model
<<PersonDAO>>

PersonCRUDFacade

implements
uses

DominoPersonDAO
encapsulates

Domino
DB

obtains
updates

creates &
uses for DB
operations

Person
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

View Layer
●

View Bean
–
–

Implements all the methods that the ”client”
sees
Talks to the service layer
●

–

E.g. through a saveUser() method that does
validation and throws a validation error to the
bean if data is not valid

Handles UI ”things”, e.g. showing validation
errors reported by the service layer
●

E.g. by connecting the validation errors from the
service layer to the corresponding components
on the XPage
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

View Layer
●

XPage
–

Access the View Bean through the scopes
●
●

–

Define the bean in faces-config.xml
… or create instance on load of page

Access properties and methods through
●
●
●

EL: e.g. UserBean.user.name
SSJS: e.g. UserBean.user.getName()
Call a ”save” method on submit, e.g. a button
with SSJS: UserBean.user.saveUser()
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

MVC - Controller
●

This is the FacesServlet in XPages
–
–

You do NOT code the controller...!!!
It handles:
●
●
●

●

Flow of incoming requests
Data streams
Interacts with the view layer for us

If you do want to change behaviour in the
controller?
–
–

You need to understand the JSF LifeCycle
Use a PhaseListener
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

The CONTROLLER
FacesServlet
renders
receives
creates
modifies
caches

View
XPage
references

PersonViewBean
uses

Model
<<PersonDAO>>

PersonCRUDFacade

DominoPersonDAO

Domin
o DB

Person
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Agenda
●
●

Demo: What is this all about?
What is MVC
●
●
●

●
●

●

Data model: Data bean & DAO
Service layer: CRUD/Facade
View layer: View bean

Why would you want to use MVC
What to do in Domino
● Data structure
● Challenges...
A word about the Demo app.
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

Why use MVC?
●
●

Avoid data-duplication (in responses)...!!!
Avoid successive lookups
–

●

Enable several ”clients” using same model, e.g.
–
–
–

●

Use Java objects in memory
Browsers (XPages)
Mobile browsers (jQuery Mobile)
Mobile apps (JSON webservices)

Independent of database architecture
–
–

Possible to change to another DBMS
Enable isolated optimizations (e.g. change to
use org.openntf.domino API)
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

Why use MVC?
●

Unit test...
–

The structure allows us to test our code at all
”Model” levels:
●
●
●

–

Data bean
DAO implementation
CRUD/Facade bean

This allows easy re-test of all code after we
have modified it
→ BETTER code...!!!!
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Agenda
●
●

Demo: What is this all about?
What is MVC
●
●
●

●
●

●

Data model: Data bean & DAO
Service layer: CRUD/Facade
View layer: View bean

Why would you want to use MVC
What to do in Domino
● Data structure
● Challenges...
A word about the Demo app.
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

MVC in Domino
●

First important fact:
–

An NSF is NOT a relational database
●

●

●

However, we can emulate that in the service
layer and treat it as such
In the DAO we can use some of the
characteristics of the NSF (e.g. response
documents) – especially in relation to existing
applications
You should create Java objects to emulate the
parent/child relations no matter what the
underlying ”technique” is. Let the DAO handle
the implementation...
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

MVC in Domino
●

Data duplication (from parent to child doc.)
can be avoided...!!
–

●

...by using your parent/child structure in the
Java objects

You will (most likely) not use any datasources
in your XPages – but refer to beans instead
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

MVC in Domino
●

Validation and error messages
–

Choose to disable client side validation
●

–

Let the service layer bean validate data on
submission
●

●

–

Will show error messages next to the fields

Capture all error messages with a field
reference (e.g. in a HashMap)
Throw a validation error if not valid

If view bean gets a validation error on save...
●
●

Read all errors (through a getter)
Iterate and ”bind” errors to all fields (through a
FacesMessage)
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

MVC in Domino
●

Security
–

Readers/authors fields
●
●

Very strong feature (compared to RDBMS's)
Should reflect and enforce chosen security
model – not be used for data retrieval etc. –
due to performance impact
–

–

But this is not really different from what you should
have been doing always...

These mechanisms should be implemented in
the DAO
●

Also includes other system fields like
$PublicAccess etc.
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

MVC in Domino
●

Beware:
–
–

–

Using Scoped beans you may need to ”Clean”
your project for changes to be effective....
Use ”LogReader” (by Majkilde – download from
openntf.org) to see messages in error-log0.xml (!!)
Sometimes ”System.out.println” can be your
friend in locating errors... ;-)
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Agenda
●
●

Demo: What is this all about?
What is MVC
●
●
●

●
●

●

Data model: Data bean & DAO
Service layer: CRUD/Facade
View layer: View bean

Why would you want to use MVC
What to do in Domino
● Data structure
● Challenges...
A word about the Demo app.
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

Demo database
●

Demo database available:
–

●

Bitbucket: https://bitbucket.org/john_dalsgaard/demo-apps.git

To set up:
–
–
–

Clone this project to your local source control
Open the cloned project as a new Java Project
in Domino Designer
From the Package Explorer view
●

–

Select Team Development and then Associate
with a new NSF...

Create the database on a server (9.0+) and
you are ready to explore the database
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

Demo database - EXTRAS
●

Caching....
–

In the service layer we have implemented
caching of ALL dataobjects in memory
●
●

●

Neat way of entering several rows
–

●

Runs FAST
Need to remember to update memory object
when updating the DB – but it is not difficult!

… and handling cursor position (!!)

Debug info written to console in lots of places
–

Phase listener shows in what phase these
messages are generated
© 2013, Dalsgaard Data A/S

Korsør, 28 November 2013

Demo database - EXTRAS
●

Uses org.openntf.domino API
–

You need to install the org.openntf.domino.jar
in your jvm/lib/ext directory.
●

●

Download from openntf.org

Validation:
–

Implemented in the service layer. Note method
to place errors against right fields using
FacesMessage
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Questions?

?
●

…. or contact one of ”Gang of Four”:
–
–
–
–

Jakob Majkilde: majkilde.dk
Per Henrik Lausten: phl-consult.dk
John Dalsgaard: www.dalsgaard-data.dk
John Foldager: izone.dk
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Contact
You are always welcome to contact me:
John Dalsgaard
Dalsgaard Data A/S
Solbjergvej 42
Solbjerg
DK-4270 Høng
Phone: +45 4914-1271
Email: john@dalsgaard-data.dk
www.dalsgaard-data.eu
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Sources
●

Great articles from Pipalia:
–

Using JSF Framework Development Standards
for your XPages Project
●
●
●
●
●
●

Article 1 - The concept and motivation...
Article 2 - Designing for MVC
Article 3 - The DAO
Article 4 - The CRUD (Facade)
Article 5 - The Bean...
Demo database
Korsør, 28 November 2013

© 2013, Dalsgaard Data A/S

Sources
●

Validators....
–
–
–

●

Pipalia: Using beans as validators
Stack overflow: Answer by Sven Hasselbach
Stack overflow: getComponent()

XPages & DB2
–

Example of alternate DAO using DB2

Weitere ähnliche Inhalte

Was ist angesagt?

Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorialprathap kumar
 
Devoxx France - Web Components, Polymer et Material Design
Devoxx France -  Web Components, Polymer et Material DesignDevoxx France -  Web Components, Polymer et Material Design
Devoxx France - Web Components, Polymer et Material DesignHoracio Gonzalez
 
JavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkJavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkAlive Kuo
 
Balisage - EXPath - A practical introduction
Balisage - EXPath - A practical introductionBalisage - EXPath - A practical introduction
Balisage - EXPath - A practical introductionFlorent Georges
 
COSCUP 2019 - The discussion between Knex.js and PostgreSQL
COSCUP 2019 - The discussion between Knex.js and PostgreSQLCOSCUP 2019 - The discussion between Knex.js and PostgreSQL
COSCUP 2019 - The discussion between Knex.js and PostgreSQLLen Chang
 
Balisage - EXPath Packaging
Balisage - EXPath PackagingBalisage - EXPath Packaging
Balisage - EXPath PackagingFlorent Georges
 
DHTML - Dynamic HTML
DHTML - Dynamic HTMLDHTML - Dynamic HTML
DHTML - Dynamic HTMLReem Alattas
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
Everything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus scriptEverything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus scriptBill Buchan
 
Yapceu2015 geneva courts
Yapceu2015 geneva courtsYapceu2015 geneva courts
Yapceu2015 geneva courtsLaurent Dami
 

Was ist angesagt? (16)

Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
How Browsers Work
How Browsers Work How Browsers Work
How Browsers Work
 
Devoxx France - Web Components, Polymer et Material Design
Devoxx France -  Web Components, Polymer et Material DesignDevoxx France -  Web Components, Polymer et Material Design
Devoxx France - Web Components, Polymer et Material Design
 
HTML 5
HTML 5HTML 5
HTML 5
 
JavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkJavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web framework
 
Balisage - EXPath - A practical introduction
Balisage - EXPath - A practical introductionBalisage - EXPath - A practical introduction
Balisage - EXPath - A practical introduction
 
Dhtml
DhtmlDhtml
Dhtml
 
COSCUP 2019 - The discussion between Knex.js and PostgreSQL
COSCUP 2019 - The discussion between Knex.js and PostgreSQLCOSCUP 2019 - The discussion between Knex.js and PostgreSQL
COSCUP 2019 - The discussion between Knex.js and PostgreSQL
 
Balisage - EXPath Packaging
Balisage - EXPath PackagingBalisage - EXPath Packaging
Balisage - EXPath Packaging
 
DOM Structure
DOM StructureDOM Structure
DOM Structure
 
How browser work
How browser workHow browser work
How browser work
 
DHTML - Dynamic HTML
DHTML - Dynamic HTMLDHTML - Dynamic HTML
DHTML - Dynamic HTML
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
How Browser Works?
How Browser Works?How Browser Works?
How Browser Works?
 
Everything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus scriptEverything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus script
 
Yapceu2015 geneva courts
Yapceu2015 geneva courtsYapceu2015 geneva courts
Yapceu2015 geneva courts
 

Ähnlich wie MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013

MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013
MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013
MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013John Dalsgaard
 
Master Data Services - used for than just data
Master Data Services - used for than just dataMaster Data Services - used for than just data
Master Data Services - used for than just dataKenneth Michael Nielsen
 
Data Analytics with DBMS
Data Analytics with DBMSData Analytics with DBMS
Data Analytics with DBMSGLC Networks
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendVlad Fedosov
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JSFestUA
 
JavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io PresentationJavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io Presentationmanolitto
 
Twelve Tasks Made Easier with IBM Domino XPages
Twelve Tasks Made Easier with IBM Domino XPagesTwelve Tasks Made Easier with IBM Domino XPages
Twelve Tasks Made Easier with IBM Domino XPagesTeamstudio
 
Airflow techtonic template
Airflow   techtonic templateAirflow   techtonic template
Airflow techtonic templateSampath Kumar
 
Introduction to Apache Airflow
Introduction to Apache AirflowIntroduction to Apache Airflow
Introduction to Apache Airflowmutt_data
 
Angular presentation
Angular presentationAngular presentation
Angular presentationMatus Szabo
 
Android training day 4
Android training day 4Android training day 4
Android training day 4Vivek Bhusal
 
Cloudsim_openstack_aws_lastunit_bsccs_cloud computing
Cloudsim_openstack_aws_lastunit_bsccs_cloud computingCloudsim_openstack_aws_lastunit_bsccs_cloud computing
Cloudsim_openstack_aws_lastunit_bsccs_cloud computingMrSameerSTathare
 
How Databases Work - for Developers, Accidental DBAs and Managers
How Databases Work - for Developers, Accidental DBAs and ManagersHow Databases Work - for Developers, Accidental DBAs and Managers
How Databases Work - for Developers, Accidental DBAs and ManagersEDB
 
Data presentation with dust js technologies backing linkedin
Data presentation with dust js   technologies backing linkedinData presentation with dust js   technologies backing linkedin
Data presentation with dust js technologies backing linkedinRuhaim Izmeth
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Sandro Mancuso
 

Ähnlich wie MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013 (20)

MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013
MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013
MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013
 
Master Data Services - used for than just data
Master Data Services - used for than just dataMaster Data Services - used for than just data
Master Data Services - used for than just data
 
Data Analytics with DBMS
Data Analytics with DBMSData Analytics with DBMS
Data Analytics with DBMS
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
 
JavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io PresentationJavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io Presentation
 
Twelve Tasks Made Easier with IBM Domino XPages
Twelve Tasks Made Easier with IBM Domino XPagesTwelve Tasks Made Easier with IBM Domino XPages
Twelve Tasks Made Easier with IBM Domino XPages
 
Airflow techtonic template
Airflow   techtonic templateAirflow   techtonic template
Airflow techtonic template
 
Introduction to Apache Airflow
Introduction to Apache AirflowIntroduction to Apache Airflow
Introduction to Apache Airflow
 
Cloud Computing & Cloud Storage
Cloud Computing & Cloud Storage Cloud Computing & Cloud Storage
Cloud Computing & Cloud Storage
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
 
Android training day 4
Android training day 4Android training day 4
Android training day 4
 
Cloudsim_openstack_aws_lastunit_bsccs_cloud computing
Cloudsim_openstack_aws_lastunit_bsccs_cloud computingCloudsim_openstack_aws_lastunit_bsccs_cloud computing
Cloudsim_openstack_aws_lastunit_bsccs_cloud computing
 
XML Data Control - Oracle OpenWorld Preview AMIS - Richard Olrichs en Wilfred...
XML Data Control - Oracle OpenWorld Preview AMIS - Richard Olrichs en Wilfred...XML Data Control - Oracle OpenWorld Preview AMIS - Richard Olrichs en Wilfred...
XML Data Control - Oracle OpenWorld Preview AMIS - Richard Olrichs en Wilfred...
 
How Databases Work - for Developers, Accidental DBAs and Managers
How Databases Work - for Developers, Accidental DBAs and ManagersHow Databases Work - for Developers, Accidental DBAs and Managers
How Databases Work - for Developers, Accidental DBAs and Managers
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
Data presentation with dust js technologies backing linkedin
Data presentation with dust js   technologies backing linkedinData presentation with dust js   technologies backing linkedin
Data presentation with dust js technologies backing linkedin
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014
 

Kürzlich hochgeladen

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

MVC and IBM XPages - from #DanNotes in Korsør (DK) 28 November 2013

  • 1. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S MVC in XPages Model – View – Controller M C V A presentation for DanNotes by John Dalsgaard
  • 2. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Me ● ● ● ● ● ● Worked with Notes since 1995 version 4.5 Java since Notes 5.0.7 (awfull Java implementation – version 1.1!!!) Large web-apps. (40.000+ users) Object Oriented approach since 1999 (yes, in LotusScript...) Now: XPages & mobile apps.... Certified Principal/advanced administrator and developer – all versions 4.6 → 8.5
  • 3. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Agenda ● ● Demo: What is this all about? What is MVC ● ● ● ● ● ● Data model: Data bean & DAO Service layer: CRUD/Facade View layer: View bean Why would you want to use MVC What to do in Domino ● Data structure ● Challenges... A word about the Demo app.
  • 4. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Demo ● ● ● ● ● Simple example Isolate data access (DAO + interface) Validation in model (service layer) Binding to Java beans through Expression Language Separate Model from View → Easy to add new ”view” component – – XPage JSON WebService
  • 5. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Demo – Data model Person Key Name Address Zip City Email YearBorn 1 n Car Key PersonKey Brand Model Colour Convertible Doors
  • 6. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013
  • 7. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Agenda ● ● Demo: What is this all about? What is MVC ● ● ● ● ● ● Data model: Data bean & DAO Service layer: CRUD/Facade View layer: View bean Why would you want to use MVC What to do in Domino ● Data structure ● Challenges... A word about the Demo app.
  • 8. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S What is MVC ● A ”design pattern” – ● Very good practice for the task at hand Separation of the tasks: – – – Model: Business rules, data model and data manipulation Viewer: Presentation of data Controller: Flow in application
  • 9. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S MVC - Model ● Java objects that implement: – Data model ● ● Contain data Manipulate data from the database – – – Specific database implementation CRUD (Create, Read, Update, Delete) Service layer ● Implement business rules – – Validation Combine data (e.g. number of years employed based on hire date)
  • 10. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S The MODEL <<PersonDAO>> Service layer PersonCRUDFacade implements uses Data model DominoPersonDAO encapsulates Domino DB creates & uses for DB operations obtains updates Person
  • 11. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Data model ● ● Is the only layer that knows the physical details of data access (documents, views, etc.) Consists of: – Data bean ● – all fields – with getter/setters – no logic DAO (Data Access Objects) ● Interface used by service layer – ● Defines all methods/operations Implementation of interface – – All handling of underlying database (e.g. recycle...) Implements necessary base functions for CRUD
  • 12. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Service layer ● This is where the business logic of the application lives – – – – ● Workflows Validations Searches Etc. Connects to the DAO implementation through its interface – Not relying on the implementation and the underlying database ”dialect” (e.g. Domino)
  • 13. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Service layer ● Do not duplicate Domino ”techniques” from the old days – – Eg. Invoice with invoice lines We have seen the pattern: line_1, line_2, line_3 in traditional Notes applicatctions ● – Create two data objects and (DAO's etc.) ● ● – Fixed number of ”relations” Invoice InvoiceLine Hide implementation details from the service layer
  • 14. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S MVC - View ● Java objects for presentation that – – – – Are used by the XPage Often one-to-one between XPages and view Beans XPage talk to the view Bean – and never to the underlying database (it doesn't know it exists!) Typically defined to the XPages via facesconfig.xml
  • 15. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S The VIEW XPage XPage references references PersonViewBean PersonEditBean uses uses Model <<PersonDAO>> PersonCRUDFacade implements uses DominoPersonDAO encapsulates Domino DB obtains updates creates & uses for DB operations Person
  • 16. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S View Layer ● View Bean – – Implements all the methods that the ”client” sees Talks to the service layer ● – E.g. through a saveUser() method that does validation and throws a validation error to the bean if data is not valid Handles UI ”things”, e.g. showing validation errors reported by the service layer ● E.g. by connecting the validation errors from the service layer to the corresponding components on the XPage
  • 17. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S View Layer ● XPage – Access the View Bean through the scopes ● ● – Define the bean in faces-config.xml … or create instance on load of page Access properties and methods through ● ● ● EL: e.g. UserBean.user.name SSJS: e.g. UserBean.user.getName() Call a ”save” method on submit, e.g. a button with SSJS: UserBean.user.saveUser()
  • 18. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 MVC - Controller ● This is the FacesServlet in XPages – – You do NOT code the controller...!!! It handles: ● ● ● ● Flow of incoming requests Data streams Interacts with the view layer for us If you do want to change behaviour in the controller? – – You need to understand the JSF LifeCycle Use a PhaseListener
  • 19. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S The CONTROLLER FacesServlet renders receives creates modifies caches View XPage references PersonViewBean uses Model <<PersonDAO>> PersonCRUDFacade DominoPersonDAO Domin o DB Person
  • 20. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Agenda ● ● Demo: What is this all about? What is MVC ● ● ● ● ● ● Data model: Data bean & DAO Service layer: CRUD/Facade View layer: View bean Why would you want to use MVC What to do in Domino ● Data structure ● Challenges... A word about the Demo app.
  • 21. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 Why use MVC? ● ● Avoid data-duplication (in responses)...!!! Avoid successive lookups – ● Enable several ”clients” using same model, e.g. – – – ● Use Java objects in memory Browsers (XPages) Mobile browsers (jQuery Mobile) Mobile apps (JSON webservices) Independent of database architecture – – Possible to change to another DBMS Enable isolated optimizations (e.g. change to use org.openntf.domino API)
  • 22. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 Why use MVC? ● Unit test... – The structure allows us to test our code at all ”Model” levels: ● ● ● – Data bean DAO implementation CRUD/Facade bean This allows easy re-test of all code after we have modified it → BETTER code...!!!!
  • 23. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Agenda ● ● Demo: What is this all about? What is MVC ● ● ● ● ● ● Data model: Data bean & DAO Service layer: CRUD/Facade View layer: View bean Why would you want to use MVC What to do in Domino ● Data structure ● Challenges... A word about the Demo app.
  • 24. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 MVC in Domino ● First important fact: – An NSF is NOT a relational database ● ● ● However, we can emulate that in the service layer and treat it as such In the DAO we can use some of the characteristics of the NSF (e.g. response documents) – especially in relation to existing applications You should create Java objects to emulate the parent/child relations no matter what the underlying ”technique” is. Let the DAO handle the implementation...
  • 25. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 MVC in Domino ● Data duplication (from parent to child doc.) can be avoided...!! – ● ...by using your parent/child structure in the Java objects You will (most likely) not use any datasources in your XPages – but refer to beans instead
  • 26. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 MVC in Domino ● Validation and error messages – Choose to disable client side validation ● – Let the service layer bean validate data on submission ● ● – Will show error messages next to the fields Capture all error messages with a field reference (e.g. in a HashMap) Throw a validation error if not valid If view bean gets a validation error on save... ● ● Read all errors (through a getter) Iterate and ”bind” errors to all fields (through a FacesMessage)
  • 27. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 MVC in Domino ● Security – Readers/authors fields ● ● Very strong feature (compared to RDBMS's) Should reflect and enforce chosen security model – not be used for data retrieval etc. – due to performance impact – – But this is not really different from what you should have been doing always... These mechanisms should be implemented in the DAO ● Also includes other system fields like $PublicAccess etc.
  • 28. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 MVC in Domino ● Beware: – – – Using Scoped beans you may need to ”Clean” your project for changes to be effective.... Use ”LogReader” (by Majkilde – download from openntf.org) to see messages in error-log0.xml (!!) Sometimes ”System.out.println” can be your friend in locating errors... ;-)
  • 29. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Agenda ● ● Demo: What is this all about? What is MVC ● ● ● ● ● ● Data model: Data bean & DAO Service layer: CRUD/Facade View layer: View bean Why would you want to use MVC What to do in Domino ● Data structure ● Challenges... A word about the Demo app.
  • 30. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 Demo database ● Demo database available: – ● Bitbucket: https://bitbucket.org/john_dalsgaard/demo-apps.git To set up: – – – Clone this project to your local source control Open the cloned project as a new Java Project in Domino Designer From the Package Explorer view ● – Select Team Development and then Associate with a new NSF... Create the database on a server (9.0+) and you are ready to explore the database
  • 31. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 Demo database - EXTRAS ● Caching.... – In the service layer we have implemented caching of ALL dataobjects in memory ● ● ● Neat way of entering several rows – ● Runs FAST Need to remember to update memory object when updating the DB – but it is not difficult! … and handling cursor position (!!) Debug info written to console in lots of places – Phase listener shows in what phase these messages are generated
  • 32. © 2013, Dalsgaard Data A/S Korsør, 28 November 2013 Demo database - EXTRAS ● Uses org.openntf.domino API – You need to install the org.openntf.domino.jar in your jvm/lib/ext directory. ● ● Download from openntf.org Validation: – Implemented in the service layer. Note method to place errors against right fields using FacesMessage
  • 33. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Questions? ? ● …. or contact one of ”Gang of Four”: – – – – Jakob Majkilde: majkilde.dk Per Henrik Lausten: phl-consult.dk John Dalsgaard: www.dalsgaard-data.dk John Foldager: izone.dk
  • 34. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Contact You are always welcome to contact me: John Dalsgaard Dalsgaard Data A/S Solbjergvej 42 Solbjerg DK-4270 Høng Phone: +45 4914-1271 Email: john@dalsgaard-data.dk www.dalsgaard-data.eu
  • 35. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Sources ● Great articles from Pipalia: – Using JSF Framework Development Standards for your XPages Project ● ● ● ● ● ● Article 1 - The concept and motivation... Article 2 - Designing for MVC Article 3 - The DAO Article 4 - The CRUD (Facade) Article 5 - The Bean... Demo database
  • 36. Korsør, 28 November 2013 © 2013, Dalsgaard Data A/S Sources ● Validators.... – – – ● Pipalia: Using beans as validators Stack overflow: Answer by Sven Hasselbach Stack overflow: getComponent() XPages & DB2 – Example of alternate DAO using DB2