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

PPT
Patterns in PHP
PDF
PyCon KR 2018 Effective Tips for Django ORM in Practice
PPTX
Fixing Magento Core for Better Performance - Ivan Chepurnyi
PDF
Extreme Development: Pair Programming
PDF
Tips for Building your First XPages Java Application
PPT
Metamorphosis from Forms to Java: A technical lead's perspective, part II
PPTX
ADF Mobile - an intro for Developers
Patterns in PHP
PyCon KR 2018 Effective Tips for Django ORM in Practice
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Extreme Development: Pair Programming
Tips for Building your First XPages Java Application
Metamorphosis from Forms to Java: A technical lead's perspective, part II
ADF Mobile - an intro for Developers

Similar to MWLUG2014 AD107 First Java App Tips (16)

PDF
Take a Trip Into the Forest: A Java Primer on Maps, Trees, and Collections
PDF
XPages Blast - ILUG 2010
PDF
engage 2014 - JavaBlast
PDF
A Notes Developer's Journey into Java
PDF
Evolve13 cq-commerce-framework
PDF
EVOLVE'13 | Enhance | Ecommerce Framework | Paolo Mottadelli
PPTX
Oracle fusion dba online training
PDF
Developing Useful APIs
PDF
MWLUG Session- AD112 - Take a Trip Into the Forest - A Java Primer on Maps, ...
PDF
Flex 3 Deep Dive
PDF
java beans
DOC
Ajava oep shopping application
DOCX
Ajava oep
PDF
JMP402 Master Class: Managed beans and XPages: Your Time Is Now
PPT
7 Tips For Better JDeveloper Experience
PDF
Connect 2014 JMP101: Java for XPages Development
Take a Trip Into the Forest: A Java Primer on Maps, Trees, and Collections
XPages Blast - ILUG 2010
engage 2014 - JavaBlast
A Notes Developer's Journey into Java
Evolve13 cq-commerce-framework
EVOLVE'13 | Enhance | Ecommerce Framework | Paolo Mottadelli
Oracle fusion dba online training
Developing Useful APIs
MWLUG Session- AD112 - Take a Trip Into the Forest - A Java Primer on Maps, ...
Flex 3 Deep Dive
java beans
Ajava oep shopping application
Ajava oep
JMP402 Master Class: Managed beans and XPages: Your Time Is Now
7 Tips For Better JDeveloper Experience
Connect 2014 JMP101: Java for XPages Development
Ad

More from Michael McGarel (8)

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

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Advanced methodologies resolving dimensionality complications for autism neur...
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
Review of recent advances in non-invasive hemoglobin estimation
sap open course for s4hana steps from ECC to s4
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectroscopy.pptx food analysis technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...

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 - graham.acres@brytek.ca Mike McGarel Blog - http://www.bleedyellow.com/blogs/McGarelGramming/ Twitter - @mmcgarel Email - mcgarelgramming@gmail.com