AD111
Harnessing the Power of Server-Side JavaScript and
Other Advanced XPage Techniques
Tim Tripcony | GROUP Experts - XMage
Stephan H. Wissel | IBM - Lotus Technology & Productivity Advisor
Agenda
●   What exactly is Server Side Java Script (SSJS)

●   Common practices: pattern & anti-pattern

●   Code samples




                                        The REAL Agenda: code, code, code

             2
Server-side JavaScript is JavaScript
●   all ECMAScript 3 keywords, operators and syntax still apply
     ▬   var myNumber = 0;
     ▬   var myArray = [ ]; // preferred over new Array();
     ▬   var myObject = { }; // preferred over new Object();
     ▬   function foo(){return "bar";}
     ▬   var depends = someBoolean ? "default" : "other";
●   ECMAScript scope rules apply, including closure
     ▬   More in the Demo section




             3
Server-side JavaScript is not JavaScript (1)
●   browser-specific globals not available
     ▬  window
     ▬  document
     ▬  location
●   Platform-specific globals and JSF-specifics
     ▬  session: current NotesSession
     ▬  database: current NotesDatabase, equal to
        session.getCurrentDatabase()
     ▬  param: URL parameters and post data
     ▬  context & facesContext: current state data and direct access to
        servlet engine




              4
Server-side JavaScript is not JavaScript (2)
●   @functions (e.g. @UserName() )
●   scope variables
     ▬ requestScope
     ▬ viewScope
     ▬ sessionScope
     ▬ applicationScope
●   Optional type declarations
●   Seamless Java™ integration




             5
Agenda
●   What exactly is Server Side Java Script (SSJS)

●   Common practices: pattern & anti-pattern

●   Code samples




             6
The use of context
●   getUser(): access to name, roles, groups, and more
●   getUrl(): no more String parsing to get query string parameters and other
    URL info
●   getUserAgent(): server-side browser detection
●   redirectToPage() / redirectToHome(): easy programmatic navigation




              7
The use of facesContext
●   getResponseWriter() / getResponseStream(): send your own output to
    the browser (like Print in LotusScript)
●   getExternalContext(): direct access to the servlet
      ▬ getRequest()
      ▬ GetResponse()
●   You need to understand the difference between the ResponseWriter
    and ResponseStream
      ▬ Writer doesn't take binary data
      ▬ Stream excludes Writer
      ▬ Can only use one per request
JavaScript Closures
●   An object returned from a function has access to variables defined within
    that function
      ▬ Includes arguments passed to the function
●   This allows for OOP constructs in JavaScript objects
      ▬ Private properties
      ▬ Private functions
      ▬ Inheritance without .prototype




              9
Take advantage of XPages' JSF heritage
●   Java Objects at your disposal
     ▬  java.util: powerful storage and iteration
     ▬  java.net: easy access to remote data
     ▬  Core JSF packages and IBM's implementation
●   Get to the servlet
●   Write your own servlet (you are on your own here)




             10
Write agent Style code in XPages
●   Control the rendering
●   Get the output writer
●   Get the output stream (one of the two)
●   Use cases:
     ▬ Replace web agent (?OpenAgent)
     ▬ Output other formats (PDF, ODF)




             11
The use of scope
●   requestScope: storage for anything needed multiple times in the same
    HTTP request
●   viewScope: survives for the life of a page - including partial and full
    refresh events
●   sessionScope: "shopping cart" storage - survives for the duration of a
    user's session, BUT can expire even if the user is still logged in (set in
    application properties to balance server performance with application
    performance)
●   applicationScope: storage shared among all users of the NSF - any data
    that numerous users are likely to need but shouldn't be queried on every
    request




              12
Anti-Pattern: What always goes wrong
●   The network is fast and reliable
●   Configuration parameters are retrieved through @DBLookup
●   Connect to JDBC without a session pool
●   Use data binding when you access data, not anything else




             13
Everybody's favorite objects
●   UI Elements
     ▬  Create a control programmatically
     ▬  Update control properties via event handlers
●   DOMUtil
     ▬  Parse DXL and other XML
●   cookie
     ▬  Set and read cookies using .put() and .get()




             14
Error Handling
●   try/catch: provide individual operations that might fail a specific response
    to failure
●   Enable “Display default error page” during development and testing
●   Create custom error pages to display uncaught exceptions




              15
Debugging
●   print(): send a single String statement to server log and console
●   _dump(): send detailed info about any object to log and console




              16
Unit Tests
        ●   Courtesy of Lorcan McDonald (IBM Lab Dublin)
        ●   Available on OpenNTF
        ●   Enables Test Driven
            Development (get used to it)




http://openntf.org/internal/ontfcatalog.nsf/topicThread.xsp?action=openDocument&documentId=9C66A4F3854E61BE852575A1003C6CAD

                           17
Reaching out to Java
●   Put source into webcontent/source
●   Add directory to Java build path
●   Package name required
●   Define like a JavaScript variable:
    var xy = new com.acme.RoadRunner();
    xy.foolCoyote(“Meep Meep”);




            18
Managed Beans
●   Concept inherited from JSF underpinnings
●   Bean is described in XML declaration
●   Can be used in JavaScript expressions
●   Automatically loaded when needed
●   Bound to a specific scope
●   Take advantage of Java capabilities (e.g. Connection pooling, threading
    etc)




             19
Agenda
●   What exactly is Server Side Java Script (SSJS)

●   Common practices: pattern & anti-pattern

●   Code samples




             20
Application Chat
●   Application Context
●   Synchronized Access
●   Closure
●   Periodic partial refresh




              21
Shopping Cart
●   Session Context
●   Closure
●   Java integration




             22
Cached Search
●   Application Context
●   Managed Bean
●   Network handling




             23
Q&A




      24
Legal Disclaimer
  ●        © IBM Corporation 2009. All Rights Reserved.


The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this publication, it is provided AS IS
without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change by IBM without notice. IBM shall not be responsible for any
damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this publication is intended to, nor shall have the effect of, creating any warranties or representations
from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software.


References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation
may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these
materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results.


IBM, the IBM logo, Lotus, and Lotusphere are trademarks of International Business Machines Corporation in the United States, other countries, or both.

Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.

All references to ACME refer to a fictitious company and are used for illustration purposes only.




                                         25

More Related Content

PDF
Ad110 - Unleash the Power of Xpages
PDF
AD113 -- IBM Lotus Notes Discussion Template: Next Generation and Other OpenN...
PDF
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
PDF
Ad102 - Extreme Makeover -- LotusScript and Java Editor Edition
PDF
Ad106 - XPages Just Keep Getting Better
PDF
AD112 -- Development and Deployment of Lotus Product Documentation Wikis
PDF
Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!
PDF
We4IT LCTY 2013 - x-pages-men - ibm domino xpages - performance in a nutshell
Ad110 - Unleash the Power of Xpages
AD113 -- IBM Lotus Notes Discussion Template: Next Generation and Other OpenN...
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad102 - Extreme Makeover -- LotusScript and Java Editor Edition
Ad106 - XPages Just Keep Getting Better
AD112 -- Development and Deployment of Lotus Product Documentation Wikis
Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!
We4IT LCTY 2013 - x-pages-men - ibm domino xpages - performance in a nutshell

What's hot (20)

PDF
AD201 - IBM Domino Application Development Today And Tomorrow
PPTX
Take Your XPages Development to the Next Level
DOC
Diff between win runner vs and qtp
PDF
AD106 - IBM Lotus Domino XPages anywhere - Write them once, See them Everywhere
ODP
DanNotes XPages Mobile Controls
PDF
Connect 2014 AD209 - Making Your Development Team More Productive With IBM Do...
PDF
From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...
PPTX
An Introduction To Model  View  Controller In XPages
PDF
A Notes Developer's Journey into Java
PDF
Workflow for XPages
PDF
Java 7 workshop
PDF
Sun Java EE 6 Overview
PDF
JMP401: Masterclass: XPages Scalability
ODP
Workflow Management with Espresso Workflow
PDF
Java EE 6 workshop at Dallas Tech Fest 2011
PDF
Java EE6 CodeCamp16 oct 2010
PDF
What’s new for Developers in IBM Domino & Domino Designer 9.0.1
PDF
AD107 Microsoft SharePoint meets IBM Lotus Domino
PPTX
Java modularization
PDF
Java EE 6 Component Model Explained
AD201 - IBM Domino Application Development Today And Tomorrow
Take Your XPages Development to the Next Level
Diff between win runner vs and qtp
AD106 - IBM Lotus Domino XPages anywhere - Write them once, See them Everywhere
DanNotes XPages Mobile Controls
Connect 2014 AD209 - Making Your Development Team More Productive With IBM Do...
From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...
An Introduction To Model  View  Controller In XPages
A Notes Developer's Journey into Java
Workflow for XPages
Java 7 workshop
Sun Java EE 6 Overview
JMP401: Masterclass: XPages Scalability
Workflow Management with Espresso Workflow
Java EE 6 workshop at Dallas Tech Fest 2011
Java EE6 CodeCamp16 oct 2010
What’s new for Developers in IBM Domino & Domino Designer 9.0.1
AD107 Microsoft SharePoint meets IBM Lotus Domino
Java modularization
Java EE 6 Component Model Explained
Ad

Similar to AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XPage Techniques (20)

PPTX
Moving to the Client - JavaFX and HTML5
PPTX
A Beard, An App, A Blender
PDF
Burns jsf-confess-2015
PDF
Kann JavaScript elegant sein?
PDF
XPages Blast - ILUG 2010
PDF
engage 2015 - Domino App Development - Where should I go now?
PDF
AD109 Navigating the Jungle of Modern Web Development
PDF
JavaOne 2014 BOF4241 What's Next for JSF?
PPT
Life In The FastLane: Full Speed XPages
PDF
Ad109 - XPages Performance and Scalability
PPTX
Introduction to JavaFx and HTML5
PDF
A guide to ADF fusion development
KEY
SSJS, NoSQL, GAE and AppengineJS
PDF
XPages Blast - Lotusphere 2011
PDF
Beginning java and flex migrating java, spring, hibernate, and maven develop...
PPT
BP204 - Take a REST and put your data to work with APIs!
PPTX
jkhefkjhl,jvhl,jesvliutguinternship.pptx
PPTX
JavaFX and HTML5 - Like Curds and Rice
PDF
Server Side Javascript
PPTX
Introduction To JavaFX 2.0
Moving to the Client - JavaFX and HTML5
A Beard, An App, A Blender
Burns jsf-confess-2015
Kann JavaScript elegant sein?
XPages Blast - ILUG 2010
engage 2015 - Domino App Development - Where should I go now?
AD109 Navigating the Jungle of Modern Web Development
JavaOne 2014 BOF4241 What's Next for JSF?
Life In The FastLane: Full Speed XPages
Ad109 - XPages Performance and Scalability
Introduction to JavaFx and HTML5
A guide to ADF fusion development
SSJS, NoSQL, GAE and AppengineJS
XPages Blast - Lotusphere 2011
Beginning java and flex migrating java, spring, hibernate, and maven develop...
BP204 - Take a REST and put your data to work with APIs!
jkhefkjhl,jvhl,jesvliutguinternship.pptx
JavaFX and HTML5 - Like Curds and Rice
Server Side Javascript
Introduction To JavaFX 2.0
Ad

More from ddrschiw (15)

PDF
Traveler preview guide
ODT
Traveler preview guide
PDF
Ad111
PDF
AD114 -- Beyond the Mobile Browser? Building Rich Mobile Applications for IBM...
PDF
Ad107 - Enhance Your Existing Applications with XPages
PDF
Ad101 - IBM Lotus Domino Designer: Full Speed Ahead!
ODP
LotusSphere 2010 - Leveraging IBM Lotus® Forms™ with IBM WebSphere® Process S...
PPT
Webform Server 351 Architecture and Overview
PPT
Introduction To IBM Lotus Forms Viewer
PPT
XPages Workshop: Concepts And Exercises
ODP
Building A Cool Web 2.0 Application With XPages
PDF
Domino X Pages
PDF
Mlb Demo1
PPT
Lotus Forms Webform Server 3.0 Overview & Architecture
PPT
Lotus Forms Webform Server 3.0 Overview & Architecture
Traveler preview guide
Traveler preview guide
Ad111
AD114 -- Beyond the Mobile Browser? Building Rich Mobile Applications for IBM...
Ad107 - Enhance Your Existing Applications with XPages
Ad101 - IBM Lotus Domino Designer: Full Speed Ahead!
LotusSphere 2010 - Leveraging IBM Lotus® Forms™ with IBM WebSphere® Process S...
Webform Server 351 Architecture and Overview
Introduction To IBM Lotus Forms Viewer
XPages Workshop: Concepts And Exercises
Building A Cool Web 2.0 Application With XPages
Domino X Pages
Mlb Demo1
Lotus Forms Webform Server 3.0 Overview & Architecture
Lotus Forms Webform Server 3.0 Overview & Architecture

Recently uploaded (20)

PDF
Bellicose Martial Arts with MMA Martial class
PPTX
Iot proposal presentation base system an
PPTX
Football_Presentation.pptx football concepts
DOCX
FIFA World Cup 2026 Tickets: Final draw for FIFA 2026 set for December at Ken...
DOCX
FIFA World Cup Tickets Los Angeles Set to Shine with Snoop Dogg as Community ...
PDF
CH-5 (1).pdfjsjdjjdjdjdjdjdjdjdjdjdjdjdndjdn
PDF
Rugby: From Tradition to Modern Glory aviator-online.net.in
DOCX
Washington Set to Shine as Hosts of FIFA World Cup.docx
DOCX
Andrew Giuliani Named to Lead FIFA World Cup Task Force.docx
DOCX
Gianni Infantino Highlights Respect and Fair Play in Global Football.docx
PDF
Uehehehrhehehejrjjrjrjrjrjdjrjjrjrjrjrjrjrjr
PDF
Andrew Sheaff: Starts, Turns and Finishes
PDF
FIFA 2026 Mexico expects to earn $3 billion from hosting the FIFA World Cup.pdf
PDF
How a Father and Angel City STH Considers Sports Fandom
DOCX
NFL Dublin Steelers Rookie Harmon Escapes Major Injury Scare.docx
DOCX
World Cup Neymar left out of Brazil squad for FIFA 2026 qualifiers.docx
PDF
Tuihiuft7hf7uhu97ef boss FF see ee so do to to
PPTX
ANATOMY-OF-A-GOOD-COACH Division of Northern Samar.pptx
DOCX
FIFA World Cup Final Houston Prepares to Host an Unforgettable World Cup Expe...
DOCX
FIFA World Cup Trump, Infantino Announce World Cup Group Draw in D.C.docx
Bellicose Martial Arts with MMA Martial class
Iot proposal presentation base system an
Football_Presentation.pptx football concepts
FIFA World Cup 2026 Tickets: Final draw for FIFA 2026 set for December at Ken...
FIFA World Cup Tickets Los Angeles Set to Shine with Snoop Dogg as Community ...
CH-5 (1).pdfjsjdjjdjdjdjdjdjdjdjdjdjdjdndjdn
Rugby: From Tradition to Modern Glory aviator-online.net.in
Washington Set to Shine as Hosts of FIFA World Cup.docx
Andrew Giuliani Named to Lead FIFA World Cup Task Force.docx
Gianni Infantino Highlights Respect and Fair Play in Global Football.docx
Uehehehrhehehejrjjrjrjrjrjdjrjjrjrjrjrjrjrjr
Andrew Sheaff: Starts, Turns and Finishes
FIFA 2026 Mexico expects to earn $3 billion from hosting the FIFA World Cup.pdf
How a Father and Angel City STH Considers Sports Fandom
NFL Dublin Steelers Rookie Harmon Escapes Major Injury Scare.docx
World Cup Neymar left out of Brazil squad for FIFA 2026 qualifiers.docx
Tuihiuft7hf7uhu97ef boss FF see ee so do to to
ANATOMY-OF-A-GOOD-COACH Division of Northern Samar.pptx
FIFA World Cup Final Houston Prepares to Host an Unforgettable World Cup Expe...
FIFA World Cup Trump, Infantino Announce World Cup Group Draw in D.C.docx

AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XPage Techniques

  • 1. AD111 Harnessing the Power of Server-Side JavaScript and Other Advanced XPage Techniques Tim Tripcony | GROUP Experts - XMage Stephan H. Wissel | IBM - Lotus Technology & Productivity Advisor
  • 2. Agenda ● What exactly is Server Side Java Script (SSJS) ● Common practices: pattern & anti-pattern ● Code samples The REAL Agenda: code, code, code 2
  • 3. Server-side JavaScript is JavaScript ● all ECMAScript 3 keywords, operators and syntax still apply ▬ var myNumber = 0; ▬ var myArray = [ ]; // preferred over new Array(); ▬ var myObject = { }; // preferred over new Object(); ▬ function foo(){return "bar";} ▬ var depends = someBoolean ? "default" : "other"; ● ECMAScript scope rules apply, including closure ▬ More in the Demo section 3
  • 4. Server-side JavaScript is not JavaScript (1) ● browser-specific globals not available ▬ window ▬ document ▬ location ● Platform-specific globals and JSF-specifics ▬ session: current NotesSession ▬ database: current NotesDatabase, equal to session.getCurrentDatabase() ▬ param: URL parameters and post data ▬ context & facesContext: current state data and direct access to servlet engine 4
  • 5. Server-side JavaScript is not JavaScript (2) ● @functions (e.g. @UserName() ) ● scope variables ▬ requestScope ▬ viewScope ▬ sessionScope ▬ applicationScope ● Optional type declarations ● Seamless Java™ integration 5
  • 6. Agenda ● What exactly is Server Side Java Script (SSJS) ● Common practices: pattern & anti-pattern ● Code samples 6
  • 7. The use of context ● getUser(): access to name, roles, groups, and more ● getUrl(): no more String parsing to get query string parameters and other URL info ● getUserAgent(): server-side browser detection ● redirectToPage() / redirectToHome(): easy programmatic navigation 7
  • 8. The use of facesContext ● getResponseWriter() / getResponseStream(): send your own output to the browser (like Print in LotusScript) ● getExternalContext(): direct access to the servlet ▬ getRequest() ▬ GetResponse() ● You need to understand the difference between the ResponseWriter and ResponseStream ▬ Writer doesn't take binary data ▬ Stream excludes Writer ▬ Can only use one per request
  • 9. JavaScript Closures ● An object returned from a function has access to variables defined within that function ▬ Includes arguments passed to the function ● This allows for OOP constructs in JavaScript objects ▬ Private properties ▬ Private functions ▬ Inheritance without .prototype 9
  • 10. Take advantage of XPages' JSF heritage ● Java Objects at your disposal ▬ java.util: powerful storage and iteration ▬ java.net: easy access to remote data ▬ Core JSF packages and IBM's implementation ● Get to the servlet ● Write your own servlet (you are on your own here) 10
  • 11. Write agent Style code in XPages ● Control the rendering ● Get the output writer ● Get the output stream (one of the two) ● Use cases: ▬ Replace web agent (?OpenAgent) ▬ Output other formats (PDF, ODF) 11
  • 12. The use of scope ● requestScope: storage for anything needed multiple times in the same HTTP request ● viewScope: survives for the life of a page - including partial and full refresh events ● sessionScope: "shopping cart" storage - survives for the duration of a user's session, BUT can expire even if the user is still logged in (set in application properties to balance server performance with application performance) ● applicationScope: storage shared among all users of the NSF - any data that numerous users are likely to need but shouldn't be queried on every request 12
  • 13. Anti-Pattern: What always goes wrong ● The network is fast and reliable ● Configuration parameters are retrieved through @DBLookup ● Connect to JDBC without a session pool ● Use data binding when you access data, not anything else 13
  • 14. Everybody's favorite objects ● UI Elements ▬ Create a control programmatically ▬ Update control properties via event handlers ● DOMUtil ▬ Parse DXL and other XML ● cookie ▬ Set and read cookies using .put() and .get() 14
  • 15. Error Handling ● try/catch: provide individual operations that might fail a specific response to failure ● Enable “Display default error page” during development and testing ● Create custom error pages to display uncaught exceptions 15
  • 16. Debugging ● print(): send a single String statement to server log and console ● _dump(): send detailed info about any object to log and console 16
  • 17. Unit Tests ● Courtesy of Lorcan McDonald (IBM Lab Dublin) ● Available on OpenNTF ● Enables Test Driven Development (get used to it) http://openntf.org/internal/ontfcatalog.nsf/topicThread.xsp?action=openDocument&documentId=9C66A4F3854E61BE852575A1003C6CAD 17
  • 18. Reaching out to Java ● Put source into webcontent/source ● Add directory to Java build path ● Package name required ● Define like a JavaScript variable: var xy = new com.acme.RoadRunner(); xy.foolCoyote(“Meep Meep”); 18
  • 19. Managed Beans ● Concept inherited from JSF underpinnings ● Bean is described in XML declaration ● Can be used in JavaScript expressions ● Automatically loaded when needed ● Bound to a specific scope ● Take advantage of Java capabilities (e.g. Connection pooling, threading etc) 19
  • 20. Agenda ● What exactly is Server Side Java Script (SSJS) ● Common practices: pattern & anti-pattern ● Code samples 20
  • 21. Application Chat ● Application Context ● Synchronized Access ● Closure ● Periodic partial refresh 21
  • 22. Shopping Cart ● Session Context ● Closure ● Java integration 22
  • 23. Cached Search ● Application Context ● Managed Bean ● Network handling 23
  • 24. Q&A 24
  • 25. Legal Disclaimer ● © IBM Corporation 2009. All Rights Reserved. The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this publication, it is provided AS IS without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change by IBM without notice. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this publication is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software. References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results. IBM, the IBM logo, Lotus, and Lotusphere are trademarks of International Business Machines Corporation in the United States, other countries, or both. Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. All references to ACME refer to a fictitious company and are used for illustration purposes only. 25