KEMBAR78
Bccon use notes objects in memory and other useful | PPTX
Use Notes objects in memory and 
other useful Java tips for XPages 
development 
Frank van der Linden
Me 
• Java/XPages/Web/Domino developer 
• Self employed at elstar IT 
• OpenNTF director 
• Speak at several national and international 
events 
• IBM Champion 2013 and 2014 
• Live in the Netherlands 
• Work everywhere 
@flinden68 
http://nl.linkedin.com/in/flinden68 
flinden68@elstarit.nl 
http://www.elstarit.nl
Disclaimer 
All the code and the demos in this session will use the Java Notes 
Objects which are part of the IBM/Lotus Notes product. 
For a modern way of Java coding with Notes Objects please use the 
OpenNTF Domino API. 
Or even better use OpenNTF essentials
Roadmap 
• Notes objects in memory 
• Use of JSON 
• MVC/Managed beans 
• Java tip for XPages 
• Date checks 
• Utility class 
• Extending classes 
• Unit test 
• Finally 
• Some bonus code
Notes objects in memory
Bad practice 
• Notes objects are not serializable 
• Will not recycled the Java way, it will keep a pointer to the C object 
• Can cause out of memory
What is serialization
XPages Java doc to the rescue
Put Notes document in memory 
• Get Notesdocument 
• Wrap Notesdocument into a DominoDocument
Get field values 
• First check if document isRecycled 
• Access field
On a XPage and more 
• In a computed field 
• In an edit box 
• Update the backend document
Demo
What about attachments 
• Get easy access to your attachments
What about attachments 
• No calculation of paths 
• Works both in XPinc and Web 
• Call the attachment URL
Demo
Use build-in JSON classes
JSON building classes 
• Part of the Extensibility API, since 8.5.2 
• Easy way to build JSON
JSON building classes 
• No concatenation of Strings 
• Faster 
• Readable code
MVC
MVC
MVC for XPages 
• Separation of responsibility 
• Cleaner code 
• Easier to maintain 
• Model = documents 
• View = XPage 
• Controller = Java managed bean
Managed beans
The requirements 
• Needs to be Serializable 
• At least one constructor without parameters 
• Needs to be registrated in the Faces-config.xml 
• Properties are private 
• And have Getters and Setters
Faces-config.xml syntax 
• In package-explorer, under WebContent WEB-INF 
• Name of the bean 
• Full qualified class name 
• Scope of the bean 
• Optional, initialize properties
Use the managed beans 
• Do the calculation in the class 
• Use Expression Language to access properties 
• Minimize use of SSJS 
• Some examples
Java tips for XPages
Utility class 
• All kind of methods 
• Always available as static class 
• I added some methods who were translated 
from SSJS
Date checks 
• Remember the TimeDifference horror 
• Java provide nice Date checks 
• Like… Date.before(Date) or Date.after(Date)
Extending a class 
• Extend a base class 
• Use the methods of the base class
Extending a class 
• Using the class 
• In a XPage
Unit test 
• Write code to test small portions of code, like methods 
• Test if the code is doing what was intended 
• Write better Java code 
• Use Mock Framework, like EasyMock or Mockito, to simulate objects
Unit test for XPages 
• More and more Java code in XPages development 
• Write Unit test for better code 
• On OpenNTF Junit test for Xpages project (thanks Christian Guedemann)
And Finally 
• Finally will always called, even after a catch 
• Use it to recycle objects and close stream readers
Thank you 
@flinden68 
http://nl.linkedin.com/in/flinden68 
http://www.elstarit.nl 
flinden68@elstarit.nl 
https://bitbucket.org/flinden68/bccon-java-demo/src
Bonus
Eventsource
Customizable Toolbar

Bccon use notes objects in memory and other useful

  • 1.
    Use Notes objectsin memory and other useful Java tips for XPages development Frank van der Linden
  • 2.
    Me • Java/XPages/Web/Dominodeveloper • Self employed at elstar IT • OpenNTF director • Speak at several national and international events • IBM Champion 2013 and 2014 • Live in the Netherlands • Work everywhere @flinden68 http://nl.linkedin.com/in/flinden68 flinden68@elstarit.nl http://www.elstarit.nl
  • 3.
    Disclaimer All thecode and the demos in this session will use the Java Notes Objects which are part of the IBM/Lotus Notes product. For a modern way of Java coding with Notes Objects please use the OpenNTF Domino API. Or even better use OpenNTF essentials
  • 4.
    Roadmap • Notesobjects in memory • Use of JSON • MVC/Managed beans • Java tip for XPages • Date checks • Utility class • Extending classes • Unit test • Finally • Some bonus code
  • 5.
  • 6.
    Bad practice •Notes objects are not serializable • Will not recycled the Java way, it will keep a pointer to the C object • Can cause out of memory
  • 7.
  • 8.
    XPages Java docto the rescue
  • 9.
    Put Notes documentin memory • Get Notesdocument • Wrap Notesdocument into a DominoDocument
  • 10.
    Get field values • First check if document isRecycled • Access field
  • 11.
    On a XPageand more • In a computed field • In an edit box • Update the backend document
  • 12.
  • 13.
    What about attachments • Get easy access to your attachments
  • 14.
    What about attachments • No calculation of paths • Works both in XPinc and Web • Call the attachment URL
  • 15.
  • 16.
  • 17.
    JSON building classes • Part of the Extensibility API, since 8.5.2 • Easy way to build JSON
  • 18.
    JSON building classes • No concatenation of Strings • Faster • Readable code
  • 19.
  • 20.
  • 21.
    MVC for XPages • Separation of responsibility • Cleaner code • Easier to maintain • Model = documents • View = XPage • Controller = Java managed bean
  • 22.
  • 23.
    The requirements •Needs to be Serializable • At least one constructor without parameters • Needs to be registrated in the Faces-config.xml • Properties are private • And have Getters and Setters
  • 24.
    Faces-config.xml syntax •In package-explorer, under WebContent WEB-INF • Name of the bean • Full qualified class name • Scope of the bean • Optional, initialize properties
  • 25.
    Use the managedbeans • Do the calculation in the class • Use Expression Language to access properties • Minimize use of SSJS • Some examples
  • 26.
  • 27.
    Utility class •All kind of methods • Always available as static class • I added some methods who were translated from SSJS
  • 28.
    Date checks •Remember the TimeDifference horror • Java provide nice Date checks • Like… Date.before(Date) or Date.after(Date)
  • 29.
    Extending a class • Extend a base class • Use the methods of the base class
  • 30.
    Extending a class • Using the class • In a XPage
  • 31.
    Unit test •Write code to test small portions of code, like methods • Test if the code is doing what was intended • Write better Java code • Use Mock Framework, like EasyMock or Mockito, to simulate objects
  • 32.
    Unit test forXPages • More and more Java code in XPages development • Write Unit test for better code • On OpenNTF Junit test for Xpages project (thanks Christian Guedemann)
  • 33.
    And Finally •Finally will always called, even after a catch • Use it to recycle objects and close stream readers
  • 34.
    Thank you @flinden68 http://nl.linkedin.com/in/flinden68 http://www.elstarit.nl flinden68@elstarit.nl https://bitbucket.org/flinden68/bccon-java-demo/src
  • 35.
  • 36.
  • 37.