Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

78
© 2013 IBM Corporation BP205 Custom Controls: Powerful, But Not Rocket Science Martin Meijer | Developer

Transcript of Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

Page 1: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

© 2013 IBM Corporation

BP205 Custom Controls: Powerful, But Not Rocket ScienceMartin Meijer | Developer

Page 2: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

2 © 2013 IBM Corporation

Legal disclaimer

© IBM Corporation 2013. All Rights Reserved.

The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this publication, it is provided AS IS without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change by IBM without notice. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this publication is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software.

References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results.

Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput or performance that any user will experience will vary depending upon many factors, including considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the storage configuration, and the workload processed. Therefore, no assurance can be given that an individual user will achieve results similar to those stated here.

All customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics may vary by customer.

Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, and/or other countries.

Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.

Microsoft and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both.

Intel, Intel Centrino, Celeron, Intel Xeon, Intel SpeedStep, Itanium, and Pentium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

UNIX is a registered trademark of The Open Group in the United States and other countries.

Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others.

All references to [insert fictitious company name] refer to a fictitious company and are used for illustration purposes only.

Page 3: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

3 © 2013 IBM Corporation

About me

Martin Meijer Developer for Saxion (University in the Netherlands) Developer for Yellow 2010 Speaker (NLLUG, DNUG, Lotusphere Idol 2010) Big Fan of XPages Big Fan of OpenNTF

Page 4: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

4 © 2013 IBM Corporation

Agenda

XPages and Custom Controls

Example 1: YouTube

Example 2: Google Maps

Example 3: Bootstrap

OpenNTF

Q&A

Page 5: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

5 © 2013 IBM Corporation

What are Custom Controls?

Reusable piece of functionality

Like a subform in Classic Domino, but better!

Can contain the same elements as an XPage

Powerful because of the custom properties

Page 6: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

6 © 2013 IBM Corporation

Design Patterns

Use an XPage as a Container for your custom Controls

Use a Custom Control as a container for a piece of functionality (Tagcloud, Search Control etc. etc)

Use a Custom Control for your GUI (think of a Layout Custom Control with Editable Area's for nesting Custom Controls)

Page 7: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

7 © 2013 IBM Corporation

Custom Properties

Page 8: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

8 © 2013 IBM Corporation

Custom Properties

Page 9: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

9 © 2013 IBM Corporation

Custom Properties

Page 10: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

10 © 2013 IBM Corporation

Custom Properties

Page 11: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

11 © 2013 IBM Corporation

Custom Properties

Page 12: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

12 © 2013 IBM Corporation

Custom Properties

Page 13: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

13 © 2013 IBM Corporation

Custom Properties

Page 14: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

14 © 2013 IBM Corporation

Custom Properties

Page 15: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

15 © 2013 IBM Corporation

Custom Properties

Page 16: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

16 © 2013 IBM Corporation

Custom Properties

Page 17: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

17 © 2013 IBM Corporation

Custom Properties

Page 18: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

18 © 2013 IBM Corporation

Custom Properties

Page 19: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

19 © 2013 IBM Corporation

Example 2: Google Maps

Page 20: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

20 © 2013 IBM Corporation

Example 2: Google Maps

Start with the documentation!

Copy & Past example, make it work.

Look for elements you can make variable, they will become custom properties.

Page 21: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

21 © 2013 IBM Corporation

https://developers.google.com/maps/documentation/javascript/tutorial#HelloWorld

Page 22: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

22 © 2013 IBM Corporation

Step 1: We declare the application as HTML5 using the <!DOCTYPE html> declaration

Page 23: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

23 © 2013 IBM Corporation

Example 2: Google Maps

Step 1: We declare the application as HTML5 using the <!DOCTYPE html> declaration

Page 24: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

24 © 2013 IBM Corporation

Step 2: We include the Maps API JavaScript using a script tag.

Page 25: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

25 © 2013 IBM Corporation

Step 2: We include the Maps API JavaScript using a script tag.

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE"></script>

Parameters: What is this?

Remember .... Read the documentation!

key=YOUR_API_KEY

sensor=SET_TOTRUE_OR_FALSE

Page 26: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

26 © 2013 IBM Corporation

Step 2: We include the Maps API JavaScript using a script tag.

key=YOUR_API_KEY

Conclusion: for this simple example we don't need this

Page 27: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

27 © 2013 IBM Corporation

Step 2: We include the Maps API JavaScript using a script tag.

sensor=SET_TOTRUE_OR_FALSE

Conclusion: It is used to determine the user's location/It is a required value, in this example we will use sensor=false

Page 28: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

28 © 2013 IBM Corporation

Step 2: We include the Maps API JavaScript using a script tag.

Page 29: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

29 © 2013 IBM Corporation

Step 2: We include the Maps API JavaScript using a script tag.

Page 30: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

30 © 2013 IBM Corporation

Step 2: We include the Maps API JavaScript using a script tag.

Page 31: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

31 © 2013 IBM Corporation

Step 3: We create a div element named "map_canvas" to hold the Map.

Page 32: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

32 © 2013 IBM Corporation

Step 3: We create a div element named "map_canvas" to hold the Map.

Page 33: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

33 © 2013 IBM Corporation

Step 3: We create a div element named "map_canvas" to hold the Map.

Page 34: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

34 © 2013 IBM Corporation

Step 4: We create a JavaScript object literal to hold a number of map properties.Step 5: We write a JavaScript function to create a "map" object.

Page 35: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

35 © 2013 IBM Corporation

Step 4: We create a JavaScript object literal to hold a number of map properties.Step 5: We write a JavaScript function to create a "map" object.

Step 6: We initialize the map object from the body tag's onload event.

Page 36: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

36 © 2013 IBM Corporation

So far ...

Page 37: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

37 © 2013 IBM Corporation

So far ...

Page 38: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

38 © 2013 IBM Corporation

What not to forgetStyle: See Hello World example ...

Page 39: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

39 © 2013 IBM Corporation

What not to forgetStyle: See Hello World example ...

Page 40: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

40 © 2013 IBM Corporation

What not to forgetMeta tag: See Hello World example ...

Page 41: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

41 © 2013 IBM Corporation

What not to forgetStyle: See Hello World example ...

Conclusion: In this example we don't use it

Page 42: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

42 © 2013 IBM Corporation

We are ready, let's try!

Page 43: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

43 © 2013 IBM Corporation

Now we can make use of Custom Properties to make things Configurable!

Page 44: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

44 © 2013 IBM Corporation

Now we can make use of Custom Properties to make things Configurable!

var mapOptions = { center: new google.maps.LatLng(-34.397, 150.644), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP };

center: new google.maps.LatLng(-34.397, 150.644),

zoom: 8,

mapTypeId: google.maps.MapTypeId.ROADMAP

Page 45: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

45 © 2013 IBM Corporation

Now we can make use of Custom Properties to make things Configurable!

Page 46: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

46 © 2013 IBM Corporation

Now we can make use of Custom Properties to make things Configurable!

Page 47: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

47 © 2013 IBM Corporation

Now we can make use of Custom Properties to make things Configurable!

Page 48: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

48 © 2013 IBM Corporation

Now we can make use of Custom Properties to make things Configurable!

Use #(javascript:compositeData.yourproperty) to replace the 'old' value in your source code

Page 49: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

49 © 2013 IBM Corporation

Now we can make use of Custom Properties to make things Configurable!

This is what you can configure with the Custom Properties when you use the custom control on your XPage

Page 50: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

50 © 2013 IBM Corporation

This was only a small piece of the Google Maps API

The Google Maps API is big!

You can download my version (not the complete API implemented) on OpenNTF

http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=Google%20Maps%20Custom%20Control

Page 51: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

51 © 2013 IBM Corporation

Example 3: Bootstrap

Page 52: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

52 © 2013 IBM Corporation

Example 3: Bootstrap

Start with the documentation!

Copy & Past example, make it work.

Look for elements you can make variable, they will become custom properties.

Page 53: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

53 © 2013 IBM Corporation

Example 3: Bootstrap

http://twitter.github.com/bootstrap/index.html

Page 54: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

54 © 2013 IBM Corporation

Example 3: Bootstrap

Unzip the downloaded bootstrap file

Drag & Drop the files (css, img and js) to your WebContent directory in the Package Explorer

Page 55: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

55 © 2013 IBM Corporation

Example 3: Bootstrap

Page 56: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

56 © 2013 IBM Corporation

Example 3: Bootstrap

Page 57: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

57 © 2013 IBM Corporation

Example 3: Bootstrap 7-10

Page 58: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

58 © 2013 IBM Corporation

Example 3: Bootstrap Create the new Custom Control

Page 59: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

59 © 2013 IBM Corporation

Example 3: Bootstrap <head> – Source code from Bootstrap starter template

Page 60: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

60 © 2013 IBM Corporation

Example 3: Bootstrap You can add the header info in your Custom Control

Page 61: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

61 © 2013 IBM Corporation

Example 3: Bootstrap <body> – Source code from Bootstrap starter template

Page 62: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

62 © 2013 IBM Corporation

Example 3: Bootstrap You can add the body info in your Custom Control

Page 63: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

63 © 2013 IBM Corporation

Example 3: Bootstrap The result ...

Page 64: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

64 © 2013 IBM Corporation

Example 3: Bootstrap make the brand configurable ...

Page 65: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

65 © 2013 IBM Corporation

Example 3: Bootstrap make the brand configurable ...

Page 66: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

66 © 2013 IBM Corporation

Example 3: Bootstrap make the brand configurable ...

Page 67: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

67 © 2013 IBM Corporation

Example 3: Bootstrap make the menu configurable ...

Page 68: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

68 © 2013 IBM Corporation

Example 3: Bootstrap make the menu configurable ...

Page 69: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

69 © 2013 IBM Corporation

Example 3: Bootstrap make the menu configurable ...

Page 70: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

70 © 2013 IBM Corporation

Example 3: Bootstrap make the menu configurable ...

Page 71: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

71 © 2013 IBM Corporation

Example 3: Bootstrap make the menu configurable ...

Page 72: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

72 © 2013 IBM Corporation

Example 3: Bootstrap make the content configurable ...

Page 73: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

73 © 2013 IBM Corporation

Example 3: Bootstrap make the content configurable ...

Page 74: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

74 © 2013 IBM Corporation

Example 3: Bootstrap make the content configurable ...

Page 75: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

75 © 2013 IBM Corporation

Example 3: Bootstrap make the content configurable ...

Page 76: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

76 © 2013 IBM Corporation

OpenNTF

Page 77: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

77 © 2013 IBM Corporation

OpenNTF Import and Export for Designer

Page 78: Presentation BP205 "Custom Controls: Powerful, But Not Rocket Science!" Connect 2013

78 © 2013 IBM Corporation

Q&A