SlideShare ist ein Scribd-Unternehmen logo
1 von 19
XPages and Java
Introduction to using Java and beans in
XPages
Per Henrik Lausten
DanNotes, November 2013
About Per Henrik Lausten
• Web developer with my own one-man company, PHL
Consult
• Lead developer on Sherlock Web
• Chairman of NotesNet – an assocation of 25
independent consultants
• Member of the board at OpenNTF – open source for IBM
Notes/Domino and IBM Connections
• Member of the board at DanNotes
• 2013 IBM Champion for IBM Collaboration Solutions
• Mentor for XPages developers in several companies
• 8K-rank on Stack Overflow with >250 answers primarily
on XPages
• Experienced XPages web application developer
Why Java and XPages?
• XPages is Java!
• XPages is based on JSF (JavaServer Faces)
– From Mastering XPages:
XPages is based on JSF version 1.1, although note that some
important fixes from JSF version 1.2 and 2.0 have been applied
to the XPages foundation layer; therefore, in reality, the XPages
base version is more like 1.1++

• Server-Side JavaScript is interpreted at runtime (so Java is
faster)
• Java gives you access to many open source libraries, a
better code editor and more
• Let’s get started!
POJO versus bean
• Plain Old Java Object (POJO)
– An ordinary Java object

• Bean
– An ordinary Java object that adheres to certain rules:
•
•
•
•
•

Serializable
No-argument constructor
Private properties
Public getter and setter methods
Configured to a specific scope

• (Notice: everything does not have to be a bean)
Well known beans in XPages
• Data sources
• Controls
– Core controls
– Container controls
– Etc.

• "Why is it crucial to understand the nature of beans when
developing XPages, even if you're not specifically writing Java code?
Because darn near everything in an XPage is a bean."

Source: What the heck is a bean? by Tim Tripcony
http://www.timtripcony.com/blog.nsf/d6plinks/TTRY-8GK6K7
Calling methods: POJO
• Simple example calling a POJO method from
Server-side JavaScript (SSJS):
var myPOJO = new dk.dannotes.PojoObject();
var output = myPOJO.method(input);

• Example: calling method using SSJS in
QuerySave event of document data source:
var myOtherPojo= new
dk.dannotes.OtherPojoObject();
myOtherPojo.process(document);
Calling methods: Bean
• SSJS
var output = myBean.method(input);

• Expression Language (binding to a field)
<xp:inputText value="#{myBean.value}"
id="fieldA" />

• myBean is defined in faces-config.xml (more
about that later)
XPages scope variables
•
•
•
•

Application (NSF)
Session (user)
View (page)
Request (request)
Examples of scoped beans
• Application scoped bean:
– general configuration

• Session scoped bean:
– user settings
– shopping cart

• View scoped bean:
– data processing similar to a document data source (for
fields, for repeats/lists, etc.)

• Request scoped bean:
– EmailBean
– PDF handling
Example: app scoped bean
package dk.dannotes;
public class Config implements Serializable {
private static final long serialVersionUID = 6469339826789980362L;
private String propertyA;
<faces-config>
private Vector propertyB;
public Config() {
init();
}
public void init() {
setPropertyA("A");
setPropertyB("B");
}

<managed-bean>
<managed-bean-name>config</managed-beanname>
<managed-beanclass>dk.dannotes.Config</managed-bean-class>
<managed-beanscope>application</managed-bean-scope>
</managed-bean>
</faces-config>

public void setPropertyA(String propertyA) {
this.propertyA = propertyA;
<xp:text
}
public String getPropertyA() {
return propertyA;
<xp:text
}
public void setPropertyB(Vector propertyB) {
this.propertyB = propertyB;
}
public Vector getPropertyB() {
return propertyB;
}
}

.. value="#{config.propertyA}" />
.. value="#{config.propertyB}" />
More examples
• Apache POI: Java API for Microsoft documents
• PDF generation
• Other binary output (see session later by John
Foldager)
• Calling backend web services
• Using 3rd party services
– Microsoft Exchange Web Services Java API
How?
• Create your Java class
• Register your Java class as a bean in faces-config.xml
• Use your bean: #{helloWorld.someVariable}

DEMO
Source: Creating your first managed bean for XPages
http://per.lausten.dk/blog/2012/02/creating-your-first-managed-bean-for-xpages.html
Using variable resolver
public static Object resolveVariable(String variable) {
return
FacesContext.getCurrentInstance().getApplication().getVariableResolver()
.resolveVariable(FacesContext.getCurrentInstance(), variable);
}

• Accessing current session:
Utils.resolveVariable("session");

• Accessing current database:
Database myDb = Utils.resolveVariable("database");

• Accessing currentDocument:
DominoDocument myXspDoc =
Utils.resolveVariable("currentDocument");

• Accessing other beans:
Utils.resolveVariable("beanName");
Using variable resolver: getInstance()
private static final String BEAN_NAME = "config";
// access to the bean
public static Config getInstance() {
return (Config) Utils.resolveVariable(BEAN_NAME);
}

String propertyA = Config.getInstance().getPropertyA();
Error messages
• Writing error messages to your Display Errors
control :
FacesContext.getCurrentInstance().addMessage(
"messages1",
new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, "")
);
To recycle or not to recycle?
• The classic IBM lotus.domino Java API
– Using Notes objects in XPages and in Java require that you recycle those
objects in order to avoid memory leaks and backend out of memory issues
– All Lotus object instances
• myDatabase.recycle();
• myView.recycle();
• myDoc.recycle();

– Don't forget columns
• Vector colValues = myView.getColumnValues();
• session.recycle(colValues);

– Don't forget NotesDateTime objects
• DateTime myDate = session.createDateTime("Now");
• myDate.recycle();

– Don't forget!

• The new OpenNTF Domino API (9.0+)
– No recycling required at all!
– See session on the OpenNTF Domino API by Paul Withers later today
Source: How to recycle Notes objects in XPages and Java
http://per.lausten.dk/blog/2013/05/how-to-recycle-notes-objects-in-xpages-and-java.html
Debugging
• Poor Man’s Debugger
– System.out.println(String msg);

• Use the XPages Debug Toolbar from Java
– DebugToolbar.get().info( String msg );

• Use the Domino server Java debugger

• Also go to Mark Leusinks session later today
Recommendation
• Use Java and go "all in"
• Use Java for as much as possible (including
your own document data sources)
• It's a journey from using SSJS only to (almost)
using Java only
• Get more inspiration in the rest of today's
sessions
Need help?
• Contact the 'Gang of four'
– Per Henrik Lausten: phl-consult.dk
– Jakob Majkilde: majkilde.dk
– John Dalsgaard: dalsgaard-data.dk
– John Foldager: izone.dk

Weitere ähnliche Inhalte

Was ist angesagt?

Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
cPanel
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPages
Mark Roden
 
My site is slow
My site is slowMy site is slow
My site is slow
hernanibf
 

Was ist angesagt? (20)

A Notes Developer's Journey into Java
A Notes Developer's Journey into JavaA Notes Developer's Journey into Java
A Notes Developer's Journey into Java
 
Take a Trip Into the Forest: A Java Primer on Maps, Trees, and Collections
Take a Trip Into the Forest: A Java Primer on Maps, Trees, and Collections Take a Trip Into the Forest: A Java Primer on Maps, Trees, and Collections
Take a Trip Into the Forest: A Java Primer on Maps, Trees, and Collections
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
 
XPages and jQuery DataTables: Simplifying View Creation while Maximizing Func...
XPages and jQuery DataTables: Simplifying View Creation while Maximizing Func...XPages and jQuery DataTables: Simplifying View Creation while Maximizing Func...
XPages and jQuery DataTables: Simplifying View Creation while Maximizing Func...
 
Uno! Deux! Three! Making Localization of XPages as Easy as 1-2-3
Uno! Deux! Three! Making Localization of XPages as Easy as 1-2-3Uno! Deux! Three! Making Localization of XPages as Easy as 1-2-3
Uno! Deux! Three! Making Localization of XPages as Easy as 1-2-3
 
5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...
5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...
5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...
 
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + ThymeleafDSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
 
Lessons learned from the worlds largest XPage project
Lessons learned from the worlds largest XPage projectLessons learned from the worlds largest XPage project
Lessons learned from the worlds largest XPage project
 
Lessons from a Dying CMS
Lessons from a Dying CMSLessons from a Dying CMS
Lessons from a Dying CMS
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPages
 
Java EE and Google App Engine
Java EE and Google App EngineJava EE and Google App Engine
Java EE and Google App Engine
 
01 java intro
01 java intro01 java intro
01 java intro
 
02 beginning code first
02   beginning code first02   beginning code first
02 beginning code first
 
jQuery Comes to XPages
jQuery Comes to XPagesjQuery Comes to XPages
jQuery Comes to XPages
 
XPages Workshop: Customizing OneUI
XPages Workshop: Customizing OneUIXPages Workshop: Customizing OneUI
XPages Workshop: Customizing OneUI
 
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
 
jQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPagesjQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPages
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
My site is slow
My site is slowMy site is slow
My site is slow
 

Andere mochten auch

SpeedGeeking! Mobile Application development with IBM XPages
SpeedGeeking! Mobile Application development with IBM XPagesSpeedGeeking! Mobile Application development with IBM XPages
SpeedGeeking! Mobile Application development with IBM XPages
Bruce Elgort
 
Apps, Apps, and More Apps: Meet the Very Best Open Source Apps from OpenNTF -...
Apps, Apps, and More Apps: Meet the Very Best Open Source Apps from OpenNTF -...Apps, Apps, and More Apps: Meet the Very Best Open Source Apps from OpenNTF -...
Apps, Apps, and More Apps: Meet the Very Best Open Source Apps from OpenNTF -...
Bruce Elgort
 
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
Stephan H. Wissel
 
Aveedo - Your application framework
Aveedo - Your application frameworkAveedo - Your application framework
Aveedo - Your application framework
We4IT Group
 
Domino OSGi Development
Domino OSGi DevelopmentDomino OSGi Development
Domino OSGi Development
Paul Fiore
 

Andere mochten auch (20)

Bootstrap4XPages - an introduction
Bootstrap4XPages - an introductionBootstrap4XPages - an introduction
Bootstrap4XPages - an introduction
 
An introduction to IBM BlueMix
An introduction to IBM BlueMixAn introduction to IBM BlueMix
An introduction to IBM BlueMix
 
SpeedGeeking! Mobile Application development with IBM XPages
SpeedGeeking! Mobile Application development with IBM XPagesSpeedGeeking! Mobile Application development with IBM XPages
SpeedGeeking! Mobile Application development with IBM XPages
 
IBM ConnectED, BP101: @IF("It\'s Really Good";"It MUST Be Notes";"Must Be Som...
IBM ConnectED, BP101: @IF("It\'s Really Good";"It MUST Be Notes";"Must Be Som...IBM ConnectED, BP101: @IF("It\'s Really Good";"It MUST Be Notes";"Must Be Som...
IBM ConnectED, BP101: @IF("It\'s Really Good";"It MUST Be Notes";"Must Be Som...
 
How to share a File using IBM Connections.Cloud
How to share a File using IBM Connections.CloudHow to share a File using IBM Connections.Cloud
How to share a File using IBM Connections.Cloud
 
How to upload a file to an IBM Connections.Cloud Community using the Plugins ...
How to upload a file to an IBM Connections.Cloud Community using the Plugins ...How to upload a file to an IBM Connections.Cloud Community using the Plugins ...
How to upload a file to an IBM Connections.Cloud Community using the Plugins ...
 
Apps, Apps, and More Apps: Meet the Very Best Open Source Apps from OpenNTF -...
Apps, Apps, and More Apps: Meet the Very Best Open Source Apps from OpenNTF -...Apps, Apps, and More Apps: Meet the Very Best Open Source Apps from OpenNTF -...
Apps, Apps, and More Apps: Meet the Very Best Open Source Apps from OpenNTF -...
 
Bootstrap4XPages webinar
Bootstrap4XPages webinarBootstrap4XPages webinar
Bootstrap4XPages webinar
 
BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...
BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...
BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...
 
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
 
Java for XPages Development
Java for XPages DevelopmentJava for XPages Development
Java for XPages Development
 
xe:objectData
xe:objectDataxe:objectData
xe:objectData
 
IBM Domino Designer: Tips and tricks for maximum productivity
IBM Domino Designer: Tips and tricks for maximum productivityIBM Domino Designer: Tips and tricks for maximum productivity
IBM Domino Designer: Tips and tricks for maximum productivity
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Aveedo - Your application framework
Aveedo - Your application frameworkAveedo - Your application framework
Aveedo - Your application framework
 
BP110: The Mobile Distruption - Why XPages Development is targeting Mobile First
BP110: The Mobile Distruption - Why XPages Development is targeting Mobile FirstBP110: The Mobile Distruption - Why XPages Development is targeting Mobile First
BP110: The Mobile Distruption - Why XPages Development is targeting Mobile First
 
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTF
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTFIBM Collaboration Solutions Community Meeting 11/11 - OpenNTF
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTF
 
Optimus XPages: An Explosion of Techniques and Best Practices
Optimus XPages: An Explosion of Techniques and Best PracticesOptimus XPages: An Explosion of Techniques and Best Practices
Optimus XPages: An Explosion of Techniques and Best Practices
 
Domino OSGi Development
Domino OSGi DevelopmentDomino OSGi Development
Domino OSGi Development
 
ICONUK 2013 - An XPager's Guide to Process Server-Side Jobs on IBM® Domino®
ICONUK 2013 - An XPager's Guide to Process Server-Side Jobs on IBM® Domino®ICONUK 2013 - An XPager's Guide to Process Server-Side Jobs on IBM® Domino®
ICONUK 2013 - An XPager's Guide to Process Server-Side Jobs on IBM® Domino®
 

Ähnlich wie XPages and Java (DanNotes 50th conference, November 2013)

SharePoint 2014: Where to save my data, for devs!
SharePoint 2014: Where to save my data, for devs!SharePoint 2014: Where to save my data, for devs!
SharePoint 2014: Where to save my data, for devs!
Ben Steinhauser
 
PowerShellForDBDevelopers
PowerShellForDBDevelopersPowerShellForDBDevelopers
PowerShellForDBDevelopers
Bryan Cafferky
 
UKLUG 2012 - XPages, Beyond the basics
UKLUG 2012 - XPages, Beyond the basicsUKLUG 2012 - XPages, Beyond the basics
UKLUG 2012 - XPages, Beyond the basics
Ulrich Krause
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
Mert Çalışkan
 

Ähnlich wie XPages and Java (DanNotes 50th conference, November 2013) (20)

OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in PracticeOpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
 
SharePoint 2014: Where to save my data, for devs!
SharePoint 2014: Where to save my data, for devs!SharePoint 2014: Where to save my data, for devs!
SharePoint 2014: Where to save my data, for devs!
 
What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?
 
[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the Basics[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the Basics
 
XPages -Beyond the Basics
XPages -Beyond the BasicsXPages -Beyond the Basics
XPages -Beyond the Basics
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
DanNotes 2013: OpenNTF Domino API
DanNotes 2013: OpenNTF Domino APIDanNotes 2013: OpenNTF Domino API
DanNotes 2013: OpenNTF Domino API
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Effective out-of-container Integration Testing
Effective out-of-container Integration TestingEffective out-of-container Integration Testing
Effective out-of-container Integration Testing
 
PowerShellForDBDevelopers
PowerShellForDBDevelopersPowerShellForDBDevelopers
PowerShellForDBDevelopers
 
OpenNTF Domino API (ODA): Super-Charging Domino Development
OpenNTF Domino API (ODA): Super-Charging Domino DevelopmentOpenNTF Domino API (ODA): Super-Charging Domino Development
OpenNTF Domino API (ODA): Super-Charging Domino Development
 
Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)
 
UKLUG 2012 - XPages, Beyond the basics
UKLUG 2012 - XPages, Beyond the basicsUKLUG 2012 - XPages, Beyond the basics
UKLUG 2012 - XPages, Beyond the basics
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
 
Ipc mysql php
Ipc mysql php Ipc mysql php
Ipc mysql php
 

Mehr von Per Henrik Lausten

Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)
Per Henrik Lausten
 

Mehr von Per Henrik Lausten (7)

Introduktion til Twitter for FCNetværk, august 2014
Introduktion til Twitter for FCNetværk, august 2014Introduktion til Twitter for FCNetværk, august 2014
Introduktion til Twitter for FCNetværk, august 2014
 
En fantastisk applikationsserver (Intravision IBM Connect 2013 Update i Århus)
En fantastisk applikationsserver (Intravision IBM Connect 2013 Update i Århus)En fantastisk applikationsserver (Intravision IBM Connect 2013 Update i Århus)
En fantastisk applikationsserver (Intravision IBM Connect 2013 Update i Århus)
 
A powerful web application server (intravision IBM Connect 2013 Update) Febru...
A powerful web application server (intravision IBM Connect 2013 Update) Febru...A powerful web application server (intravision IBM Connect 2013 Update) Febru...
A powerful web application server (intravision IBM Connect 2013 Update) Febru...
 
Source Control with Domino Designer 8.5.3 and Git (DanNotes, November 28, 2012)
Source Control with Domino Designer 8.5.3 and Git (DanNotes, November 28, 2012)Source Control with Domino Designer 8.5.3 and Git (DanNotes, November 28, 2012)
Source Control with Domino Designer 8.5.3 and Git (DanNotes, November 28, 2012)
 
Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)
 
XPages Extension Library - Create an app in 1 hour (almost)
XPages Extension Library - Create an app in 1 hour (almost)XPages Extension Library - Create an app in 1 hour (almost)
XPages Extension Library - Create an app in 1 hour (almost)
 
My view on XPages
My view on XPagesMy view on XPages
My view on XPages
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Kürzlich hochgeladen (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 

XPages and Java (DanNotes 50th conference, November 2013)

  • 1. XPages and Java Introduction to using Java and beans in XPages Per Henrik Lausten DanNotes, November 2013
  • 2. About Per Henrik Lausten • Web developer with my own one-man company, PHL Consult • Lead developer on Sherlock Web • Chairman of NotesNet – an assocation of 25 independent consultants • Member of the board at OpenNTF – open source for IBM Notes/Domino and IBM Connections • Member of the board at DanNotes • 2013 IBM Champion for IBM Collaboration Solutions • Mentor for XPages developers in several companies • 8K-rank on Stack Overflow with >250 answers primarily on XPages • Experienced XPages web application developer
  • 3. Why Java and XPages? • XPages is Java! • XPages is based on JSF (JavaServer Faces) – From Mastering XPages: XPages is based on JSF version 1.1, although note that some important fixes from JSF version 1.2 and 2.0 have been applied to the XPages foundation layer; therefore, in reality, the XPages base version is more like 1.1++ • Server-Side JavaScript is interpreted at runtime (so Java is faster) • Java gives you access to many open source libraries, a better code editor and more • Let’s get started!
  • 4. POJO versus bean • Plain Old Java Object (POJO) – An ordinary Java object • Bean – An ordinary Java object that adheres to certain rules: • • • • • Serializable No-argument constructor Private properties Public getter and setter methods Configured to a specific scope • (Notice: everything does not have to be a bean)
  • 5. Well known beans in XPages • Data sources • Controls – Core controls – Container controls – Etc. • "Why is it crucial to understand the nature of beans when developing XPages, even if you're not specifically writing Java code? Because darn near everything in an XPage is a bean." Source: What the heck is a bean? by Tim Tripcony http://www.timtripcony.com/blog.nsf/d6plinks/TTRY-8GK6K7
  • 6. Calling methods: POJO • Simple example calling a POJO method from Server-side JavaScript (SSJS): var myPOJO = new dk.dannotes.PojoObject(); var output = myPOJO.method(input); • Example: calling method using SSJS in QuerySave event of document data source: var myOtherPojo= new dk.dannotes.OtherPojoObject(); myOtherPojo.process(document);
  • 7. Calling methods: Bean • SSJS var output = myBean.method(input); • Expression Language (binding to a field) <xp:inputText value="#{myBean.value}" id="fieldA" /> • myBean is defined in faces-config.xml (more about that later)
  • 8. XPages scope variables • • • • Application (NSF) Session (user) View (page) Request (request)
  • 9. Examples of scoped beans • Application scoped bean: – general configuration • Session scoped bean: – user settings – shopping cart • View scoped bean: – data processing similar to a document data source (for fields, for repeats/lists, etc.) • Request scoped bean: – EmailBean – PDF handling
  • 10. Example: app scoped bean package dk.dannotes; public class Config implements Serializable { private static final long serialVersionUID = 6469339826789980362L; private String propertyA; <faces-config> private Vector propertyB; public Config() { init(); } public void init() { setPropertyA("A"); setPropertyB("B"); } <managed-bean> <managed-bean-name>config</managed-beanname> <managed-beanclass>dk.dannotes.Config</managed-bean-class> <managed-beanscope>application</managed-bean-scope> </managed-bean> </faces-config> public void setPropertyA(String propertyA) { this.propertyA = propertyA; <xp:text } public String getPropertyA() { return propertyA; <xp:text } public void setPropertyB(Vector propertyB) { this.propertyB = propertyB; } public Vector getPropertyB() { return propertyB; } } .. value="#{config.propertyA}" /> .. value="#{config.propertyB}" />
  • 11. More examples • Apache POI: Java API for Microsoft documents • PDF generation • Other binary output (see session later by John Foldager) • Calling backend web services • Using 3rd party services – Microsoft Exchange Web Services Java API
  • 12. How? • Create your Java class • Register your Java class as a bean in faces-config.xml • Use your bean: #{helloWorld.someVariable} DEMO Source: Creating your first managed bean for XPages http://per.lausten.dk/blog/2012/02/creating-your-first-managed-bean-for-xpages.html
  • 13. Using variable resolver public static Object resolveVariable(String variable) { return FacesContext.getCurrentInstance().getApplication().getVariableResolver() .resolveVariable(FacesContext.getCurrentInstance(), variable); } • Accessing current session: Utils.resolveVariable("session"); • Accessing current database: Database myDb = Utils.resolveVariable("database"); • Accessing currentDocument: DominoDocument myXspDoc = Utils.resolveVariable("currentDocument"); • Accessing other beans: Utils.resolveVariable("beanName");
  • 14. Using variable resolver: getInstance() private static final String BEAN_NAME = "config"; // access to the bean public static Config getInstance() { return (Config) Utils.resolveVariable(BEAN_NAME); } String propertyA = Config.getInstance().getPropertyA();
  • 15. Error messages • Writing error messages to your Display Errors control : FacesContext.getCurrentInstance().addMessage( "messages1", new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, "") );
  • 16. To recycle or not to recycle? • The classic IBM lotus.domino Java API – Using Notes objects in XPages and in Java require that you recycle those objects in order to avoid memory leaks and backend out of memory issues – All Lotus object instances • myDatabase.recycle(); • myView.recycle(); • myDoc.recycle(); – Don't forget columns • Vector colValues = myView.getColumnValues(); • session.recycle(colValues); – Don't forget NotesDateTime objects • DateTime myDate = session.createDateTime("Now"); • myDate.recycle(); – Don't forget! • The new OpenNTF Domino API (9.0+) – No recycling required at all! – See session on the OpenNTF Domino API by Paul Withers later today Source: How to recycle Notes objects in XPages and Java http://per.lausten.dk/blog/2013/05/how-to-recycle-notes-objects-in-xpages-and-java.html
  • 17. Debugging • Poor Man’s Debugger – System.out.println(String msg); • Use the XPages Debug Toolbar from Java – DebugToolbar.get().info( String msg ); • Use the Domino server Java debugger • Also go to Mark Leusinks session later today
  • 18. Recommendation • Use Java and go "all in" • Use Java for as much as possible (including your own document data sources) • It's a journey from using SSJS only to (almost) using Java only • Get more inspiration in the rest of today's sessions
  • 19. Need help? • Contact the 'Gang of four' – Per Henrik Lausten: phl-consult.dk – Jakob Majkilde: majkilde.dk – John Dalsgaard: dalsgaard-data.dk – John Foldager: izone.dk