tips for building your first xpages java application

61
Tips for Building Your First XPages Java Application Tweet about this event And mention us: @Teamstudio @TLCCLTD @mmcgarel @gacres99 Dec. 2, 2014

Upload: teamstudio

Post on 08-Jul-2015

648 views

Category:

Technology


0 download

DESCRIPTION

XPages and Java go together like bicycles and great exercise. But much like you wouldn't attempt a hundred mile bicycle ride on your first day, Java is best learned by starting small and building on your accomplishments. Planning, preparation, and realistic goals are keys to becoming proficient at using Java in your XPages applications. Come learn as two long-time developers, Mike and Graham, share their experiences on their Java treks and demonstrate some of what they learned as they build a Java-based shopping cart in an XPages application.

TRANSCRIPT

Page 1: Tips for Building your First XPages Java Application

Tips for Building Your First XPages Java Application

Tweet about this event

And mention us: @Teamstudio @TLCCLTD

@mmcgarel @gacres99

Dec. 2, 2014

Page 2: Tips for Building your First XPages Java Application

@Teamstudio

teamstudio.com

@TLCCLTD

tlcc.com

Courtney CarterInbound Marketing Specialist

Teamstudio

Page 3: Tips for Building your First XPages Java Application

Who We Are

• Teamstudio’s background is in creating tools for

collaborative computing in mid-size and large

enterprises, primarily for IBM Notes

• Easy-to-use tools for developers and administrators

• 2300+ active customers, 47 countries

• Offices in US, UK, and Japan

• Entered mobile space in 2010 with Unplugged: easy

mobilization of Notes apps to Blackberry, Android

and iOS

Page 4: Tips for Building your First XPages Java Application

Teamstudio Unplugged

• Your mobile Domino server: take your IBM Notes

apps with you!

• End-users access Notes applications from mobile

devices whether online or offline

• Leverages the powerful technology of XPages

• Unplugged v3.1

Page 5: Tips for Building your First XPages Java Application

Unplugged Templates

• Continuity – Mobile offline access to BCM programs

• OneView Approvals – Expense approvals; anywhere, anytime

• CustomerView – lightweight CRM framework for field sales and field service teams• Contacts – customer information database

• Activities – customer activity log

• Media – mobile offline file storage and access

Page 6: Tips for Building your First XPages Java Application

XControls

• Set of Controls for IBM Domino XPage developers

working on new XPages apps and on app

modernization projects

• Re-write of the Teamstudio Unplugged Controls

project, but adds full support for PC browser-based

user interfaces as well as mobile interfaces

• Enables XPage developers to create controls that

are responsive

• Learn more: http://xcontrols.org

Page 7: Tips for Building your First XPages Java Application

Teamstudio Services

• Professional services for project management,

development, administration, and modernizationo Modernization Services

o Unplugged Developer Assistance Program

o Application Upgrade Analysis

o Application Complexity Analysis

o Application Usage Auditing

• http://www.teamstudio.com/solutions/services/

Page 8: Tips for Building your First XPages Java Application

• Modernization Services promotion:

o Now through December 15, sign up to learn about our Modernization Services, and

be automatically entered to win an iPhone 6.

Page 9: Tips for Building your First XPages Java Application

1

#XPages

Your Hosts Today:

Howard GreenbergTLCC

@TLCCLtd

Paul Della-NebbiaTLCC

@PaulDN

Tips for your First JavaXPages Application

Page 10: Tips for Building your First XPages Java Application

How can TLCC Help YOU!

2

• Private classes at your location or virtual

•XPages Development

•Support Existing Apps

•Administration

• Let us help you become an expert XPages developer!

• Delivered via Notes

• XPages

• Development

• Admin

• UserSelf-

Paced Courses

Mentoring

Instructor-Led

Classes

Application Development

and Consulting

Free Demo

Courses!

Page 11: Tips for Building your First XPages Java Application

TLCC Java Courses and Package for XPages Developers

Java 1 for XPages Development (9.0)• Covers the Java Language

Java 2 for XPages Development • Debugging

• Expression Language

• JavaBeans and Managed Beans

• Third Party Java Libraries

• Exporting to PDF and Excel files

• On Sale for $599, save $300

Java for XPages Package

• Has both Java courses

• On Sale for only $999, save $500

3

Click here for more information on the Java courses

Sale prices good through 12/31/2014

Page 12: Tips for Building your First XPages Java Application

Upcoming and Recorded Webinars

4

• Future webinars for 2015 to be announced later this month

www.tlcc.com/xpages-webinar

View Previous Webinars(use url above)

Page 13: Tips for Building your First XPages Java Application

Asking Questions – Q and A at the end

5

Use the Orange Arrow button to expand the GoToWebinar panel

Then ask your questions in the Questions pane!

We will answer your questions verbally at the end of the webinar

Page 14: Tips for Building your First XPages Java Application

Your Presenters Today:

6

#XPages

Graham AcresBrytek Systems

@gacres99

Mike McGarelCzarnowski@mmcgarel

Page 15: Tips for Building your First XPages Java Application

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

Page 16: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Mike McGarel

Collaborative Solutions Developer at Czarnowski Display Service, Inc.

Working with Notes/Domino since version 4.6

Working on the Web for over 14 years

OpenNTF Contributor

Maintain MWLUG site

Page 17: Tips for Building your First XPages Java Application

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

Page 18: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Midwest Biking Inc.

Page 19: Tips for Building your First XPages Java Application

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

Resources

Questions

Page 20: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

You Are Here Where to Begin?

Page 21: Tips for Building your First XPages Java Application

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”;

Page 22: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

“I Don’t Know What I Don’t Know”

Page 23: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

“Checking the Roadmap”

Websites galore!

Blog posts

Notes in 9 videos

Books

Colleagues

Java APIs

Conference sessions

Page 24: Tips for Building your First XPages Java Application

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

Page 25: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Don’t “Reinvent the Bicycle Wheel”

Example: String class has 72 methods!

Page 26: Tips for Building your First XPages Java Application

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

Page 27: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

“Planning your route”

Page 28: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Application Design

Front end UI

Functionality

Back end structure

Client-side code

Server-side code

Page 29: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Java Class Design

Java classes needed

Order

Shopping cart

Cart item

Optional

Utility

Catalog

Order

ShoppingCart

CartItem CartItem CartItem CartItem CartItem

Page 30: Tips for Building your First XPages Java Application

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)

Page 31: Tips for Building your First XPages Java Application

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

Page 32: Tips for Building your First XPages Java Application

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;

}

}

Page 33: Tips for Building your First XPages Java Application

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;

} }

Page 34: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Shopping Cart Demo

Page 35: Tips for Building your First XPages Java Application

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

Page 36: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

LinkedHashMap Class Methods

.containsKey()

.get()

.isEmpty()

.put(K key, V value)

.size()

.values()

Page 37: Tips for Building your First XPages Java Application

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>

Page 38: Tips for Building your First XPages Java Application

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();

}

}

Page 39: Tips for Building your First XPages Java Application

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;

Page 40: Tips for Building your First XPages Java Application

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;

}

Page 41: Tips for Building your First XPages Java Application

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));

}

Page 42: Tips for Building your First XPages Java Application

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

Page 43: Tips for Building your First XPages Java Application

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>

Page 44: Tips for Building your First XPages Java Application

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);

}

Page 45: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Lessons Learned and Cool Tips

Page 46: Tips for Building your First XPages Java Application

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

Page 47: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Lesson Learned #2 – Date Fields

Java Calendar object

Page 48: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Lesson Learned #2 – Date Fields

Page 49: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Lesson Learned #2 – Date Fields

Page 50: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Lesson Learned #3 – Try / Catch Blocks

Error management

Different from LotusScript

Not just errors

Page 51: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Lesson Learned #4 – Managed Beans

Not every Java object need to be a managed bean

Where a bean is managed is also important

ApplicationScope

SessionScope

ViewScope

RequestScope

Depending on need, may copy from one scope to another

Be careful!

Page 52: Tips for Building your First XPages Java Application

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

Page 53: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Cool Tip #2 – Comparing Strings

Here is where your LotusScript background can bite you ‘LotusScript

Dim strName As String

If (strName = “Schwinn”) Then

‘ do some processing

End If

//Java

String strName = "Schwinn";

if (strName == "Trek") {

// do some processing

// will always be FALSE!

}

Use this! if (strName.equals("Trek")) {

// do some processing

}

Page 54: Tips for Building your First XPages Java Application

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

Page 55: Tips for Building your First XPages Java Application

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 OpenNTF Domino API

Collaboration Today http://collaborationtoday.info

StackOverflow http://stackoverflow.com

How to Program With Java http://www.howtoprogramwithjava.com

Page 57: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

“You’re On Your Way”

Page 58: Tips for Building your First XPages Java Application

AD107: Don’t Put the Cart . . .

Page 59: Tips for Building your First XPages Java Application

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]

Page 60: Tips for Building your First XPages Java Application

Questions????

7

Use the Orange Arrow button to expand the GoToWebinar panel

Then ask your questions in the Questions panel!

Remember, we will answer your questions verbally

Page 61: Tips for Building your First XPages Java Application

Upcoming Events:ConnectED, Orlando in JanuaryEngage, March 30/31 in Ghent, Belgium

Question and Answer Time!

8

Teamstudio [email protected]

877-228-6178

TLCC [email protected] [email protected]

888-241-8522 or 561-953-0095

Howard Greenberg

#XPages

@mmcgarel

@gacres99

@TLCCLtd

@Teamstudio

@PaulDN

Paul Della-Nebbia Courtney Carter

To learn more about Java in XPages:Special offer for webinar attendees on TLCC’s Java Package

Mike McGarel Graham Acres