SlideShare a Scribd company logo
AD107: Don’t Put the Cart Before the 
Source: Tips for Building Your First 
XPages Java Application 
Graham Acres, President, Brytek Systems Inc. 
Mike McGarel, Collaborative Solutions Developer, 
Czarnowski Display Services, Inc. 
MWLUG 2014
AD107: Don’t Put the Cart . . . 
Graham Acres 
 IBM Lotus Notes Developer/Designer 
since v2.1 
 Brytek is an IBM Business Partner based 
in Vancouver, Canada 
 Currently focus on application 
development (Social Business, XPages, 
Mobile) 
 OpenNTF Contributor 
 Away from work 
Cyclist, Ride to Conquer Cancer
AD107: Don’t Put the Cart . . . 
Mike McGarel 
 Collaborative Solutions Developer at 
Czarnowski Display Services 
Working with Notes/Domino since version 4.6 
Working on the Web for over 14 years 
 OpenNTF Contributor 
 Maintain MWLUG site
AD107: Don’t Put the Cart . . . 
Disclaimer 
We are 
Professionals, but 
NOT Experts (in 
this case anyway) 
 This advice is 
likely not Best 
Practices, but it is 
our experience in 
learning Java
AD107: Don’t Put the Cart . . . 
Midwest Biking Inc.
AD107: Don’t Put the Cart . . . 
Agenda 
 Where to Begin 
 Planning Your Application 
 Shopping Cart Demo 
 Let’s Look at the Code 
 Lessons Learned and Cool Tips 
 OpenNTF Domino API 
 Resources 
 Questions
AD107: Don’t Put the Cart . . . 
Where to Begin? You Are Here
AD107: Don’t Put the Cart . . . 
Why Java? 
 XPages is built on Java 
 SSJS is converted to Java 
 Futureproofs YOUR skill set 
 Syntax is not that different from LotusScript 
‘LotusScript 
Dim strName As String 
strName = “Schwinn” 
//Java 
String strName = “Schwinn”;
AD107: Don’t Put the Cart . . . 
“I Don’t Know What I Don’t Know”
AD107: Don’t Put the Cart . . . 
“Checking the Roadmap” 
Websites galore! 
 Blog posts 
 Notes in 9 videos 
 Books 
 Colleagues 
 Java APIs 
 Conference sessions
AD107: Don’t Put the Cart . . . 
Java “Rules of the Road” 
 Case sensitive 
 Mandatory semicolon; 
 XPages version is Java 6 
 Data types: Primitive vs. Class (double <> Double) 
Primitive (lower case), e.g., double, int, char 
Class (proper case), e.g., Double, Integer, String
AD107: Don’t Put the Cart . . . 
Don’t “Reinvent the Bicycle Wheel” 
 Example: String class has 72 methods!
AD107: Don’t Put the Cart . . . 
Collections 
 You will almost always use collections whenever you 
interact with a database 
 LotusScript has them, e.g., NotesDocumentCollection, 
ViewEntryCollection 
 Java has many more, e.g., ArrayList, Vector, HashMap, 
TreeMap, LinkedHashSet, TreeSet 
 List – stores index position 
 Map – has a key-value pairing 
 Set – no duplicates
AD107: Don’t Put the Cart . . . 
“Planning your route”
AD107: Don’t Put the Cart . . . 
Application Design 
 Front end UI 
 Functionality 
 Back end structure 
 Client-side code 
 Server-side code
AD107: Don’t Put the Cart . . . 
Java Class Design 
 Java classes needed 
 Order 
 Shopping cart 
 Cart item 
 Optional 
 Utility 
 Catalog 
Order 
ShoppingCart 
CCaartrIttIetemm CCaartrIttIetemm CartItem
AD107: Don’t Put the Cart . . . 
Class Elements 
 Properties 
 Often tied to form or document fields, e.g., 
 unit price for a cart item 
 if the cart contains items 
 Methods 
 Standard getters / setters 
 Custom, e.g., calculate cost (quantity x price)
AD107: Don’t Put the Cart . . . 
Java Beans (a canned explanation) 
A Java object defined by specific standards 
 Public Java class 
 Serializable 
 Private properties (optional) 
 Public constructor with no arguments 
 Public methods
AD107: Don’t Put the Cart . . . 
Sample Bean (outside) 
package com.mbi.shopping; 
import java.io.Serializable; 
/* other possible libraries */ 
public class Sample implements Serializable { 
private static final long serialVersionUID = 1L; 
private String myText; 
public Sample() { 
} 
public String getMyText() { 
return myText; 
} 
public void setMyText (String txt) { 
this.myText = txt; 
} 
}
AD107: Don’t Put the Cart . . . 
Sample Bean (inside) 
package com.mbi.shopping; 
import java.io.Serializable; 
/* other possible libraries */ 
public class Sample implements Serializable { 
private static final long serialVersionUID = 1L; 
private String myText; 
public Sample() { 
} 
public String getMyText() { 
return myText; 
} 
public void setMyText (String txt) { 
this.myText = txt; 
} 
}
AD107: Don’t Put the Cart . . . 
Shopping Cart Demo
AD107: Don’t Put the Cart . . . 
ShoppingCart Class 
 Properties: 
private LinkedHashMap<String,CartItem> cart; 
private BigDecimal totalCost; 
Why a LinkedHashMap ? 
 Keeps the insertion order 
 Uses a key,value structure 
 The key can be used on other parts of the page, 
e.g., "Add to Cart" button rendering
AD107: Don’t Put the Cart . . . 
LinkedHashMap Class Methods 
 .containsKey() 
 .get() 
 .isEmpty() 
 .put(K key, V value) 
 .size() 
 .values()
AD107: Don’t Put the Cart . . . 
XPage Code for “Add to Cart” Button 
<xp:button value="Add to Cart" id="btnAddToCart"> 
<xp:this.rendered> 
<![CDATA[#{javascript:var productId = productEntry.getColumnValues()[0]; 
!Order.containsKey(productId)}]]> 
</xp:this.rendered> 
<xp:eventHandler event="onclick" submit="true” refreshMode="partial" 
refreshId="content"> 
<xp:this.action> 
<![CDATA[#{javascript:var id = productEntry.getColumnValues()[0]; 
var name = productEntry.getColumnValues()[1]; 
var price = 
new java.math.BigDecimal(productEntry.getColumnValues()[4].toString()); 
var qty = new java.lang.Double(1); 
Order.addCartItem(name,id,price,qty)}]]> 
</xp:this.action> 
</xp:eventHandler> 
</xp:button>
AD107: Don’t Put the Cart . . . 
ShoppingCart Class Code for addCartItem 
public ShoppingCart() { 
this.cart = new LinkedHashMap<String,CartItem>(); 
totalCost = new BigDecimal(0); 
} 
public void addCartItem (String name, String id, 
BigDecimal price, Double quantity) { 
try { 
CartItem cartItem = new CartItem(); 
cartItem.load(name,id,price,quantity); 
cart.put(id,cartItem); 
calcTotalCost(); 
} catch (Exception ex) { 
ex.printStackTrace(); 
} 
}
AD107: Don’t Put the Cart . . . 
CartItem Class Properties 
Contains only what’s needed for processing, e.g., 
Name, ID, price, quantity, cost: 
private String itemName; 
private String itemId; 
private BigDecimal itemPrice; 
private Double itemQuantity; 
private BigDecimal itemCost;
AD107: Don’t Put the Cart . . . 
CartItem Class Methods 
Mostly getters / setters, e.g., 
public Double getItemQuantity() { 
return itemQuantity; 
} 
public void setItemQuantity (Double qty) { 
this.itemQuantity = qty; 
}
AD107: Don’t Put the Cart . . . 
CartItem Loading Method 
In ShoppingCart Class: 
CartItem cartItem = new CartItem(); 
cartItem.load(name,id,price,quantity); 
cart.put(id,cartItem); 
In CartItem Class: 
public void load (String name, String id, 
BigDecimal price, Double quantity) { 
setItemName(name); 
setItemId(id); 
setItemPrice(price); 
setItemQuantity(quantity); 
setItemCost(calcItemCost(quantity)); 
}
AD107: Don’t Put the Cart . . . 
Order Class 
 Managed bean 
 Instantly available 
 Loaded in faces-config.xml file 
Tip: available in 9.0.1 through Domino 
Designer without Package Explorer. 
Preferences > Domino Designer > 
Application Navigator > Application 
Configuration > Faces-config
AD107: Don’t Put the Cart . . . 
Faces-config.xml Sample 
<?xml version="1.0" encoding="UTF-8"?> 
<faces-config> 
<managed-bean> 
<managed-bean-name>Order</managed-bean-name> 
<managed-bean-class>com.mbi.shopping.Order 
</managed-bean-class> 
<managed-bean-scope>session</managed-bean-scope> 
</managed-bean> 
<!--AUTOGEN-START-BUILDER: Automatically generated 
by IBM Domino Designer. Do not modify.--> 
<!--AUTOGEN-END-BUILDER: End of automatically 
generated section--> 
</faces-config>
AD107: Don’t Put the Cart . . . 
Order Class Properties and Methods 
 Contains ShoppingCart property 
Wrapped methods for easier access, e.g., 
private ShoppingCart cart; 
public Order() { 
this.cart = new ShoppingCart(); 
} 
public void addCartItem (String name, String id, BigDecimal price, 
Double quantity) { 
this.cart.addCartItem(name,id,price,quantity); 
} 
public void removeCartItem (String key) { 
this.cart.removeCartItem(key); 
}
AD107: Don’t Put the Cart . . . 
Lessons Learned and Cool Tips
AD107: Don’t Put the Cart . . . 
Lesson Learned #1 – Number Field 
 Number value becomes JavaScript number 
(thanks to JSF number converter) 
 Equivalent to Java Double (the class not the primitive) 
 Originally used Integer class for the item quantity 
Integer or int reference results in type mismatch error 
Error not showing up using System.out.println 
Error display control worked, because problem was 
on the XPage itself
AD107: Don’t Put the Cart . . . 
Lesson Learned #2 – Date Fields 
 Java Calendar object
AD107: Don’t Put the Cart . . . 
Lesson Learned #2 – Date Fields
AD107: Don’t Put the Cart . . . 
Lesson Learned #2 – Date Fields
AD107: Don’t Put the Cart . . . 
Lesson Learned #3 – Try / Catch Blocks 
 Error management 
 Different from LotusScript 
 Not just errors
AD107: Don’t Put the Cart . . . 
Cool Tip #1 – To Do Reminder 
 Add to your Java code for a handy reminder 
Written as: TODO in any comment line
AD107: Don’t Put the Cart . . . 
OpenNTF Domino API 
 What is it? 
 Should you use it? 
 Pros / Cons 
 http://www.openntf.org/main.nsf/project.xsp?r=project/OpenNTF%20Domino%20API 
 https://github.com/OpenNTF/org.openntf.domino/commits/M4.5
AD107: Don’t Put the Cart . . . 
Resources: Tutorials and Books 
 Tutorial on Collections 
http://docs.oracle.com/javase/tutorial/collections/interfaces/index.html 
 Head First Java
AD107: Don’t Put the Cart . . . 
Resources: Websites 
 Java 6 API 
http://docs.oracle.com/javase/6/docs/api/ 
 Notes in 9 
http://www.notesin9.com 
 OpenNTF 
http://www.opentf.org 
 Collaboration Today 
http://collaborationtoday.info 
 StackOverflow 
http://stackoverflow.com 
 How to Program With Java 
http://www.howtoprogramwithjava.com
AD107: Don’t Put the Cart . . . 
Resources: Community Blogs 
 Jesse Gallagher 
https://frostillic.us 
 Nathan Freeman 
http://nathanfreeman.wordpress.com 
 Paul Withers 
http://www.intec.co.uk/author/paulwithers/ 
 Declan Lynch 
http://www.qtzar.com 
 Tim Tripcony 
http://www.timtripcony.com/blog.nsf 
 Niklas Heidloff 
http://heidloff.net/
AD107: Don’t Put the Cart . . . 
“You’re On Your Way”
AD107: Don’t Put the Cart . . .
AD107: Don’t Put the Cart . . . 
Thank You! 
Graham Acres 
Blog - http://grahamacres.wordpress.com/ 
Twitter - @gacres99 
Email - graham.acres@brytek.ca 
Mike McGarel 
Blog - http://www.bleedyellow.com/blogs/McGarelGramming/ 
Twitter - @mmcgarel 
Email - mcgarelgramming@gmail.com

More Related Content

Similar to MWLUG2014 AD107 First Java App Tips (20)

PPT
Effecient javascript
mpnkhan
 
ODP
Bring the fun back to java
ciklum_ods
 
PPT
JavaOne TS-5098 Groovy SwingBuilder
Andres Almiray
 
PDF
購物車程式架構簡介
Jace Ju
 
PPTX
Writing your own WordPress themes and plugins
Stephanie Wells
 
PDF
Magento Attributes - Fresh View
Alex Gotgelf
 
PDF
Supercharge Flutter declarative UI with code generation
Emanuele Papa
 
PPT
GWT MVP Case Study
David Chandler
 
PPT
Svcc Building Rich Applications with Groovy's SwingBuilder
Andres Almiray
 
PDF
WooCommerce CRUD and Data Store by Akeda Bagus
WordCamp Indonesia
 
PDF
OOPS JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
LEARN C#
adroitinfogen
 
PPTX
Designing REST API automation tests in Kotlin
Dmitriy Sobko
 
PPT
Working Effectively With Legacy Code
Naresh Jain
 
KEY
Geek Moot '09 -- Smarty 101
Ted Kulp
 
PPTX
Facade Design Pattern
Livares Technologies Pvt Ltd
 
PDF
Dependency injection in Drupal 8
Alexei Gorobets
 
PDF
Ajax-Tutorial
tutorialsruby
 
PPTX
iOS,From Development to Distribution
Tunvir Rahman Tusher
 
PDF
Webpack Encore Symfony Live 2017 San Francisco
Ryan Weaver
 
Effecient javascript
mpnkhan
 
Bring the fun back to java
ciklum_ods
 
JavaOne TS-5098 Groovy SwingBuilder
Andres Almiray
 
購物車程式架構簡介
Jace Ju
 
Writing your own WordPress themes and plugins
Stephanie Wells
 
Magento Attributes - Fresh View
Alex Gotgelf
 
Supercharge Flutter declarative UI with code generation
Emanuele Papa
 
GWT MVP Case Study
David Chandler
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Andres Almiray
 
WooCommerce CRUD and Data Store by Akeda Bagus
WordCamp Indonesia
 
OOPS JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
LEARN C#
adroitinfogen
 
Designing REST API automation tests in Kotlin
Dmitriy Sobko
 
Working Effectively With Legacy Code
Naresh Jain
 
Geek Moot '09 -- Smarty 101
Ted Kulp
 
Facade Design Pattern
Livares Technologies Pvt Ltd
 
Dependency injection in Drupal 8
Alexei Gorobets
 
Ajax-Tutorial
tutorialsruby
 
iOS,From Development to Distribution
Tunvir Rahman Tusher
 
Webpack Encore Symfony Live 2017 San Francisco
Ryan Weaver
 

More from Michael McGarel (8)

PPTX
Next Level Coding
Michael McGarel
 
PPTX
Object(ive) Thinking
Michael McGarel
 
PDF
BP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
Michael McGarel
 
ODP
How To Build a Multi-Field Search Page For Your XPages Application
Michael McGarel
 
PPTX
XPages Workshop: Customizing OneUI
Michael McGarel
 
ODP
Two CCs of Layout -- Stat
Michael McGarel
 
ODP
XPages - The Ties That Bind
Michael McGarel
 
ODP
Approaches to Enhancing the User Experience
Michael McGarel
 
Next Level Coding
Michael McGarel
 
Object(ive) Thinking
Michael McGarel
 
BP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
Michael McGarel
 
How To Build a Multi-Field Search Page For Your XPages Application
Michael McGarel
 
XPages Workshop: Customizing OneUI
Michael McGarel
 
Two CCs of Layout -- Stat
Michael McGarel
 
XPages - The Ties That Bind
Michael McGarel
 
Approaches to Enhancing the User Experience
Michael McGarel
 
Ad

Recently uploaded (20)

PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
PDF
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
The Growing Value and Application of FME & GenAI
Safe Software
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Practical Applications of AI in Local Government
OnBoard
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Ad

MWLUG2014 AD107 First Java App Tips

  • 1. AD107: Don’t Put the Cart Before the Source: Tips for Building Your First XPages Java Application Graham Acres, President, Brytek Systems Inc. Mike McGarel, Collaborative Solutions Developer, Czarnowski Display Services, Inc. MWLUG 2014
  • 2. AD107: Don’t Put the Cart . . . Graham Acres  IBM Lotus Notes Developer/Designer since v2.1  Brytek is an IBM Business Partner based in Vancouver, Canada  Currently focus on application development (Social Business, XPages, Mobile)  OpenNTF Contributor  Away from work Cyclist, Ride to Conquer Cancer
  • 3. AD107: Don’t Put the Cart . . . Mike McGarel  Collaborative Solutions Developer at Czarnowski Display Services Working with Notes/Domino since version 4.6 Working on the Web for over 14 years  OpenNTF Contributor  Maintain MWLUG site
  • 4. AD107: Don’t Put the Cart . . . Disclaimer We are Professionals, but NOT Experts (in this case anyway)  This advice is likely not Best Practices, but it is our experience in learning Java
  • 5. AD107: Don’t Put the Cart . . . Midwest Biking Inc.
  • 6. AD107: Don’t Put the Cart . . . Agenda  Where to Begin  Planning Your Application  Shopping Cart Demo  Let’s Look at the Code  Lessons Learned and Cool Tips  OpenNTF Domino API  Resources  Questions
  • 7. AD107: Don’t Put the Cart . . . Where to Begin? You Are Here
  • 8. AD107: Don’t Put the Cart . . . Why Java?  XPages is built on Java  SSJS is converted to Java  Futureproofs YOUR skill set  Syntax is not that different from LotusScript ‘LotusScript Dim strName As String strName = “Schwinn” //Java String strName = “Schwinn”;
  • 9. AD107: Don’t Put the Cart . . . “I Don’t Know What I Don’t Know”
  • 10. AD107: Don’t Put the Cart . . . “Checking the Roadmap” Websites galore!  Blog posts  Notes in 9 videos  Books  Colleagues  Java APIs  Conference sessions
  • 11. AD107: Don’t Put the Cart . . . Java “Rules of the Road”  Case sensitive  Mandatory semicolon;  XPages version is Java 6  Data types: Primitive vs. Class (double <> Double) Primitive (lower case), e.g., double, int, char Class (proper case), e.g., Double, Integer, String
  • 12. AD107: Don’t Put the Cart . . . Don’t “Reinvent the Bicycle Wheel”  Example: String class has 72 methods!
  • 13. AD107: Don’t Put the Cart . . . Collections  You will almost always use collections whenever you interact with a database  LotusScript has them, e.g., NotesDocumentCollection, ViewEntryCollection  Java has many more, e.g., ArrayList, Vector, HashMap, TreeMap, LinkedHashSet, TreeSet  List – stores index position  Map – has a key-value pairing  Set – no duplicates
  • 14. AD107: Don’t Put the Cart . . . “Planning your route”
  • 15. AD107: Don’t Put the Cart . . . Application Design  Front end UI  Functionality  Back end structure  Client-side code  Server-side code
  • 16. AD107: Don’t Put the Cart . . . Java Class Design  Java classes needed  Order  Shopping cart  Cart item  Optional  Utility  Catalog Order ShoppingCart CCaartrIttIetemm CCaartrIttIetemm CartItem
  • 17. AD107: Don’t Put the Cart . . . Class Elements  Properties  Often tied to form or document fields, e.g.,  unit price for a cart item  if the cart contains items  Methods  Standard getters / setters  Custom, e.g., calculate cost (quantity x price)
  • 18. AD107: Don’t Put the Cart . . . Java Beans (a canned explanation) A Java object defined by specific standards  Public Java class  Serializable  Private properties (optional)  Public constructor with no arguments  Public methods
  • 19. AD107: Don’t Put the Cart . . . Sample Bean (outside) package com.mbi.shopping; import java.io.Serializable; /* other possible libraries */ public class Sample implements Serializable { private static final long serialVersionUID = 1L; private String myText; public Sample() { } public String getMyText() { return myText; } public void setMyText (String txt) { this.myText = txt; } }
  • 20. AD107: Don’t Put the Cart . . . Sample Bean (inside) package com.mbi.shopping; import java.io.Serializable; /* other possible libraries */ public class Sample implements Serializable { private static final long serialVersionUID = 1L; private String myText; public Sample() { } public String getMyText() { return myText; } public void setMyText (String txt) { this.myText = txt; } }
  • 21. AD107: Don’t Put the Cart . . . Shopping Cart Demo
  • 22. AD107: Don’t Put the Cart . . . ShoppingCart Class  Properties: private LinkedHashMap<String,CartItem> cart; private BigDecimal totalCost; Why a LinkedHashMap ?  Keeps the insertion order  Uses a key,value structure  The key can be used on other parts of the page, e.g., "Add to Cart" button rendering
  • 23. AD107: Don’t Put the Cart . . . LinkedHashMap Class Methods  .containsKey()  .get()  .isEmpty()  .put(K key, V value)  .size()  .values()
  • 24. AD107: Don’t Put the Cart . . . XPage Code for “Add to Cart” Button <xp:button value="Add to Cart" id="btnAddToCart"> <xp:this.rendered> <![CDATA[#{javascript:var productId = productEntry.getColumnValues()[0]; !Order.containsKey(productId)}]]> </xp:this.rendered> <xp:eventHandler event="onclick" submit="true” refreshMode="partial" refreshId="content"> <xp:this.action> <![CDATA[#{javascript:var id = productEntry.getColumnValues()[0]; var name = productEntry.getColumnValues()[1]; var price = new java.math.BigDecimal(productEntry.getColumnValues()[4].toString()); var qty = new java.lang.Double(1); Order.addCartItem(name,id,price,qty)}]]> </xp:this.action> </xp:eventHandler> </xp:button>
  • 25. AD107: Don’t Put the Cart . . . ShoppingCart Class Code for addCartItem public ShoppingCart() { this.cart = new LinkedHashMap<String,CartItem>(); totalCost = new BigDecimal(0); } public void addCartItem (String name, String id, BigDecimal price, Double quantity) { try { CartItem cartItem = new CartItem(); cartItem.load(name,id,price,quantity); cart.put(id,cartItem); calcTotalCost(); } catch (Exception ex) { ex.printStackTrace(); } }
  • 26. AD107: Don’t Put the Cart . . . CartItem Class Properties Contains only what’s needed for processing, e.g., Name, ID, price, quantity, cost: private String itemName; private String itemId; private BigDecimal itemPrice; private Double itemQuantity; private BigDecimal itemCost;
  • 27. AD107: Don’t Put the Cart . . . CartItem Class Methods Mostly getters / setters, e.g., public Double getItemQuantity() { return itemQuantity; } public void setItemQuantity (Double qty) { this.itemQuantity = qty; }
  • 28. AD107: Don’t Put the Cart . . . CartItem Loading Method In ShoppingCart Class: CartItem cartItem = new CartItem(); cartItem.load(name,id,price,quantity); cart.put(id,cartItem); In CartItem Class: public void load (String name, String id, BigDecimal price, Double quantity) { setItemName(name); setItemId(id); setItemPrice(price); setItemQuantity(quantity); setItemCost(calcItemCost(quantity)); }
  • 29. AD107: Don’t Put the Cart . . . Order Class  Managed bean  Instantly available  Loaded in faces-config.xml file Tip: available in 9.0.1 through Domino Designer without Package Explorer. Preferences > Domino Designer > Application Navigator > Application Configuration > Faces-config
  • 30. AD107: Don’t Put the Cart . . . Faces-config.xml Sample <?xml version="1.0" encoding="UTF-8"?> <faces-config> <managed-bean> <managed-bean-name>Order</managed-bean-name> <managed-bean-class>com.mbi.shopping.Order </managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> <!--AUTOGEN-START-BUILDER: Automatically generated by IBM Domino Designer. Do not modify.--> <!--AUTOGEN-END-BUILDER: End of automatically generated section--> </faces-config>
  • 31. AD107: Don’t Put the Cart . . . Order Class Properties and Methods  Contains ShoppingCart property Wrapped methods for easier access, e.g., private ShoppingCart cart; public Order() { this.cart = new ShoppingCart(); } public void addCartItem (String name, String id, BigDecimal price, Double quantity) { this.cart.addCartItem(name,id,price,quantity); } public void removeCartItem (String key) { this.cart.removeCartItem(key); }
  • 32. AD107: Don’t Put the Cart . . . Lessons Learned and Cool Tips
  • 33. AD107: Don’t Put the Cart . . . Lesson Learned #1 – Number Field  Number value becomes JavaScript number (thanks to JSF number converter)  Equivalent to Java Double (the class not the primitive)  Originally used Integer class for the item quantity Integer or int reference results in type mismatch error Error not showing up using System.out.println Error display control worked, because problem was on the XPage itself
  • 34. AD107: Don’t Put the Cart . . . Lesson Learned #2 – Date Fields  Java Calendar object
  • 35. AD107: Don’t Put the Cart . . . Lesson Learned #2 – Date Fields
  • 36. AD107: Don’t Put the Cart . . . Lesson Learned #2 – Date Fields
  • 37. AD107: Don’t Put the Cart . . . Lesson Learned #3 – Try / Catch Blocks  Error management  Different from LotusScript  Not just errors
  • 38. AD107: Don’t Put the Cart . . . Cool Tip #1 – To Do Reminder  Add to your Java code for a handy reminder Written as: TODO in any comment line
  • 39. AD107: Don’t Put the Cart . . . OpenNTF Domino API  What is it?  Should you use it?  Pros / Cons  http://www.openntf.org/main.nsf/project.xsp?r=project/OpenNTF%20Domino%20API  https://github.com/OpenNTF/org.openntf.domino/commits/M4.5
  • 40. AD107: Don’t Put the Cart . . . Resources: Tutorials and Books  Tutorial on Collections http://docs.oracle.com/javase/tutorial/collections/interfaces/index.html  Head First Java
  • 41. AD107: Don’t Put the Cart . . . Resources: Websites  Java 6 API http://docs.oracle.com/javase/6/docs/api/  Notes in 9 http://www.notesin9.com  OpenNTF http://www.opentf.org  Collaboration Today http://collaborationtoday.info  StackOverflow http://stackoverflow.com  How to Program With Java http://www.howtoprogramwithjava.com
  • 42. AD107: Don’t Put the Cart . . . Resources: Community Blogs  Jesse Gallagher https://frostillic.us  Nathan Freeman http://nathanfreeman.wordpress.com  Paul Withers http://www.intec.co.uk/author/paulwithers/  Declan Lynch http://www.qtzar.com  Tim Tripcony http://www.timtripcony.com/blog.nsf  Niklas Heidloff http://heidloff.net/
  • 43. AD107: Don’t Put the Cart . . . “You’re On Your Way”
  • 44. AD107: Don’t Put the Cart . . .
  • 45. AD107: Don’t Put the Cart . . . Thank You! Graham Acres Blog - http://grahamacres.wordpress.com/ Twitter - @gacres99 Email - [email protected] Mike McGarel Blog - http://www.bleedyellow.com/blogs/McGarelGramming/ Twitter - @mmcgarel Email - [email protected]