![Page 1: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/1.jpg)
Use Notes objects in memory and other useful Java tips for XPages
developmentFrank van der Linden
![Page 2: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/2.jpg)
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://www.elstarit.nl
http://nl.linkedin.com/in/flinden68
![Page 3: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/3.jpg)
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
![Page 4: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/4.jpg)
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
![Page 5: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/5.jpg)
Notes objects in memory
![Page 6: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/6.jpg)
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
![Page 7: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/7.jpg)
What is serialization
![Page 8: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/8.jpg)
XPages Java doc to the rescue
![Page 9: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/9.jpg)
Put Notes document in memory
• Get Notesdocument
• Wrap Notesdocument into a DominoDocument
![Page 10: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/10.jpg)
Get field values
• First check if document isRecycled
• Access field
![Page 11: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/11.jpg)
On a XPage and more
• In a computed field
• In an edit box
• Update the backend document
![Page 12: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/12.jpg)
Demo
![Page 13: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/13.jpg)
What about attachments
• Get easy access to your attachments
![Page 14: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/14.jpg)
What about attachments
• No calculation of paths• Works both in XPinc and Web
• Call the attachment URL
![Page 15: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/15.jpg)
Demo
![Page 16: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/16.jpg)
Use build-in JSON classes
![Page 17: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/17.jpg)
JSON building classes
• Part of the Extensibility API, since 8.5.2• Easy way to build JSON
![Page 18: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/18.jpg)
JSON building classes
• No concatenation of Strings• Faster• Readable code
![Page 19: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/19.jpg)
MVC
![Page 20: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/20.jpg)
MVC
![Page 21: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/21.jpg)
MVC for XPages
• Separation of responsibility
• Cleaner code
• Easier to maintain
• Model = documents
• View = XPage
• Controller = Java managed bean
![Page 22: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/22.jpg)
Managed beans
![Page 23: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/23.jpg)
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
![Page 24: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/24.jpg)
Faces-config.xml syntax
• In package-explorer, under WebContentWEB-INF• Name of the bean• Full qualified class name• Scope of the bean• Optional, initialize properties
![Page 25: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/25.jpg)
Use the managed beans
• Do the calculation in the class• Use Expression Language to access properties• Minimize use of SSJS• Some examples
![Page 26: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/26.jpg)
Java tips for XPages
![Page 27: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/27.jpg)
Utility class
• All kind of methods• Always available as static class• I added some methods who were translated
from SSJS
![Page 28: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/28.jpg)
Date checks
• Remember the TimeDifference horror• Java provide nice Date checks• Like… Date.before(Date) or Date.after(Date)
![Page 29: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/29.jpg)
Extending a class
• Extend a base class• Use the methods of the base class
![Page 30: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/30.jpg)
Extending a class
• Using the class
• In a XPage
![Page 31: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/31.jpg)
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
![Page 32: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/32.jpg)
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)
![Page 33: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/33.jpg)
And Finally
• Finally will always called, even after a catch
• Use it to recycle objects and close stream readers
![Page 34: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/34.jpg)
Thank you
@flinden68
http://www.elstarit.nl
http://nl.linkedin.com/in/flinden68
https://bitbucket.org/flinden68/bccon-java-demo/src
![Page 35: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/35.jpg)
Bonus
![Page 36: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/36.jpg)
Eventsource
![Page 37: ics user group dev day_2014 use notes objects in memory and other useful](https://reader034.vdocuments.site/reader034/viewer/2022042700/55665ddfd8b42aa21e8b4a13/html5/thumbnails/37.jpg)
Customizable Toolbar