Dev2011 Maher Understandingyouroptions
Dev2011 Maher Understandingyouroptions
Options with
JavaScript to Build
Powerful and Dynamic
XP
XPages Applications
A li ti
Russell Maher
RGM Consulting
2011 Wellesley Information Services. All rights reserved.
In This Session
Understand your JavaScript options
Understand the differences between Dojo and jQuery and how to
use both toolkits
S how
See h to t use th
the powerful
f l XPage
XP repeatt control
t l
1
What Well Cover
Understanding JavaScript Toolkit Options
Using Dojo in XPages
Using jQuery in XPages
Working with XPage Repeat Controls
Combining repeat controls with jQuery
Wrap-up
3
Understanding JavaScript Toolkit Options Dojo
Dojo Toolkit
First released in 2006
Code here has not gone through the testing and validation
required in Dojo and Dijit
f Developed
D l d and d submitted
b itt d b
by th
the community
it
5
Understanding JavaScript Toolkit Options Others?
Other JavaScript Libraries/Toolkits?
Sure! Take your pick!
f Lots of developers
Animation effects
AJAX utilities
JSON manipulation
9
Using Dojo in XPages
Dojo comes Free in XPages!
IBM will continue to expand Dojo support
Becoming Dojo proficient will be a good time investment for you
as an XP
XPage developer
d l
You are already using Dojo in XPages when you select certain
properties
Requiring fields
Date/Time Picker
10
Dojo Basics
Dojo basic concepts
1. Load the Dojo library with your page
5. Tell Dojo to parse all of the Dojo objects and connect it all once
the page has been loaded
11
Dojo + XPages Basics
How do they do that in XPages?
Domino loads standard Dojo PLUS xspClientDojo.js JavaScript
library at runtime
xspClientDojo
Cli tD j performs
f the
th Dojo
D j basics
b i in i an XPage-specific
XP ifi way
Examples:
f attachValidator
f getFieldValue
f attachEvent
f attachPartial
12
13
Dojo + XPages Load/Require
14
15
Dojo Slider: Adding the Dojo Module
Add the dijit.form.Slider as an XPage resource
16
17
Dojo Slider: Adding to XPage (cont.)
Slider Script Details
18
19
Dojo Slider Demo
Using a Dojo Slider
20
Dojo NumberSpinner
An XPage Text Field Control can be a Dojo NumberSpinner
21
Dojo Demos
Using a Dojo NumberSpinner, Dojo Dialog, and other Dojo widgets
22
Sometimes you might find another JavaScript tool that will give
you what you want faster
23
What Well Cover
Understanding JavaScript Toolkit Options
Using Dojo in XPages
Using jQuery in XPages
Working with XPage Repeat Controls
Combining repeat controls with jQuery
Wrap-up
24
You can definitely combine Dojo and jQuery in the same XPage
Having more JavaScript skills is always better when trying to
meet customer application requirements
25
jQuery Basics
jQuery basic concepts
1. Load the jQuery library with your page
26
Uh, no
Which means you cannot add it to your XPage the usual way as
an XPage resource
27
Load jQuery Libraries Options
Options
Add the jQuery.js files to your application as a file resource
28
29
Launch jQuery
Launch the jQuery code on document ready
Once the page has fully loaded then jQuery will modify the
document as needed to process the code
jQ
jQuery uses a $ as shorthand
h th d for
f jQuery
jQ
30
31
jQuery Rounded Corners Plug-In
Rounded Corners plug-in rounds corner of specific elements
No images needed
Can nest rounded corner elements within others
Steps
1. Add jQuery library
32
33
jQuery Validation Plug-In
Validation plug-in provides client-side validation
Very flexible
Very reusable
Works nicely with XPages with standard caveats
Handling XPage ID
34
Validation Details
Validation steps
1. Add jQuery library
35
Validation Rules
Validation rules can be added
as class attributes
f required
f required email
f required date
f required number
or programmatically
f rules:
l { username: { required:
i d ttrue, minlength:
i l th 22,
maxlength:60 }}
36
37
Validate the Form
Write a client-side function to
use the validator to
38
39
Validate the Form Button
40
Validation Demo
Using the jQuery Validation Plug-In
41
More Plug-Ins
There are thousands of jQuery plug-ins
datePicker
A little different than the Dojo version
OneUI independent
Autocomplete
AKA type ahead
More
M functional
f ti l thanth theth pretty
tt panell type
t ahead
h d
Very configurable
42
43
What Well Cover
Understanding JavaScript Toolkit Options
Using Dojo in XPages
Using jQuery in XPages
Working with XPage Repeat Controls
Combining repeat controls with jQuery
Wrap-up
44
JavaScript Code
Other controls
Custom controls
45
Working with XPage Repeat Controls Uses
Repeat controls can be used
To generate HTML tables
46
Using a View
Repeat control with a view
Add a view data source to XPage
47
Using a Field
Repeat control with a multi-value field
Add a document data source to XPage
Select the data source and choose a field as your repeat control
d t source
data
f Makes the most sense with a multi-value field or there will be
no repeating
48
Using an Array
Repeat control with an array
Write JavaScript that produces an array
f new Array(1,2,3,4)
f @DbColumn("","Data",1)
49
Using a Collection
Repeat control with a document collection
Write JavaScript that returns a document collection
50
Repeat Content
Once you have your collection of somethings you need some
thing to repeat
Static Text or HTML
Computed
C t d Field
Fi ld C
Control
t l
Label Control
Link Control
51
Repeat Text
Static text or HTML
You can add static text inside the repeat control in the source
52
53
Repeat Control Properties (cont.)
Collection Name and Index Name
54
Repeat Limit
The number of entries to show at a time
55
Using Repeat Variables
Controls placed inside a repeat control can refer to the objects
that are being repeated
From the inner controls you refer to the Collection name property
value to access the current object in the repeat control
Once a control is dropped inside a repeat control, the Collection
name property value is a choice to configure the data form the
inner control
Computed Field Control
Label Control
Link Control
56
57
Working with XPage Repeat Controls
Using Repeat Controls
58
59
Combining Repeat Controls with jQuery
Every XPage control is pretty powerful
Drag-and-drop pre-built
Cross-browser
Combining
C bi i Repeat
R t Controls
C t l with
ith other
th controls
t l andd JJavaScript
S i t
gives your applications Super Powers!
You can do things you could never do with Domino before
XPages
60
61
Heres How
Heres how we do this
I want to have my documents listed in a page
62
f Add jQuery code to our XPage so that when the page loads,
the HTML table is transformed into a sortable table
63
Heres How (cont.)
Heres how we do this (cont.)
I want to be able to edit part of any document right from the
view
I wantt to
t tell
t ll you which
hi h fields
fi ld I wantt tto be
b able
bl to
t edit
dit
I want all of the same validation and functionality I have when I
edit the document normally to still work when I edit the
document from a view
f Uh this ones a little trickier
64
65
Combining Repeat Controls with jQuery
Repeat Controls + jQuery = Super Powers
66
67
Resources
W3Schools.com Good for Things Web
www.w3schools.com
Fi f + Fi
Firefox Firebug
b
http://getfirefox.com
http://getfirebug.com
68
Resources (cont.)
Douglas Crockford JavaScript Guru
www.crockford.com
www.crockford.com/javascript
www.json.org/js.html
M ill D
Mozilla Developers
l G
Guide
id
https://developer.mozilla.org/en/JavaScript/Guide
69
Resources (cont.)
BuiltWith Trends Site that trends Web site development tool use
http://trends.builtwith.com
XPage Wiki
www.lotus.com/ldd/ddwiki.nsf
XPages Blog
http://xpagesblog.com
XPages Wiki Independent
http://xpageswiki.com
70
Resources (cont.)
Taskspeed Performance Of CSJS Frameworks
http://dante.dojotoolkit.org/taskspeed/
71
7 Key Points to Take Home
JavaScript toolkits make you more productive
Cooler JavaScript makes your users happier
Dojo comes with XPages and will continue to get more support
Dojo uses widgets, jQuery uses plug-ins
jQuery is very popular and works great with XPages
It may not be possible to do what you want to do with just one
JavaScript toolkit
Repeat Controls give you Super Powers!
72
Your Turn!