Mais conteúdo relacionado
Semelhante a XPages Blast - Lotusphere 2011 (20)
XPages Blast - Lotusphere 2011
- 1. © 2011 IBM Corporation
BP211 XPages Blast
Matt White | Lead Developer | Elguji Software
Tim Clark | Tech Sales | IBM Lotus
- 2. 2© 2011 IBM Corporation
Matt White
• Lead Developer at
• Creators of IdeaJam™ and IQJam™
• Creator of XPages101.net
• Founder member of the LDC
2
- 3. 3© 2011 IBM Corporation
Tim Clark
• 17 years in IBM® Lotus®
• Support, Sales and Channel
• Creator of the X Cast, XPages podcast
• http://www.thexcast.net
3
- 4. 4© 2011 IBM Corporation
Products we’re using
• IBM® Lotus Domino® Server 8.5.2
• Most of the session is based on 8.5.2, where we use earlier versions we’ll mention it
• IBM® Lotus Notes® 8.5.2
• IBM® Lotus Domino Designer® 8.5.2
4
- 5. 5© 2011 IBM Corporation
Agenda
• General Programming Tips
• Debugging
• UI
• Notes Client
• Dojo
5
- 6. 6© 2011 IBM Corporation
Tip Grading
• Beginner
• Intermediate
• Advanced
6
- 7. 7© 2011 IBM Corporation
Sample Database
• You can download a database which demonstrates a lot of tips we talk about
here:
http://tinyurl.com/ls11xpagesblast
7
- 8. 8© 2011 IBM Corporation
General Programming Tips
• Those useful bits and pieces that make your coding day fly by!
8
- 9. 9© 2011 IBM Corporation
1. Scoped Variables
• applicationScope
• use to store data for all users of the app
• sessionScope
• use to store data for the current user
• viewScope
• use to store data for the current page
• requestScope
• use to store data for a single round trip to the server
9
scopedvariables.xsp
- 10. 10© 2011 IBM Corporation
2. Repeat ANY data
• Repeat controls can be used with any type of data, not just view data.
• As long as the data is a list of some sort and you know how to reference it
• @Functions can return a string or a list, to make sure the results work, use this
$A function:
• http://tinyurl.com/xpbrepeats
10
repeats.xsp
- 11. 11© 2011 IBM Corporation
3. Calling an Agent in 8.5.0 or 8.5.1
• Don’t do it unless you really need to!
• Running code as a different user (e.g. an admin)
• You’ll probably end up having to save the document twice, so it’s very
expensive.
• However, if you really have to...
var agent:NotesAgent = database.getAgent(“myagent”);
agent.runOnServer(noteid);
• Or you can always call an old style agent URL using AJAX (we’ll show you how
later on)
11
- 12. 12© 2011 IBM Corporation
4. Calling an Agent in 8.5.2 +
• In 8.5.2 you can call an agent and pass an “in memory” document to it:
Agent.runWithDocumentContext(NotesDocument)
• There are also three different types of session object available:
• session - the current user’s session
• sessionAsSigner - a session running as the XPage signer
• sessionAsSignerWithFullAccess - a session running as the XPage signer
giving full admin rights
• Running SSJS is always going to be faster than calling an agent
12
- 13. 13© 2011 IBM Corporation
5. ACLs in XPages
• If not done, people may be able to create documents that you are not expecting
• Go to All Properties > Data > ACL and add ACL settings
• Settings can be made for:
• Default
• Anonymous
• Individuals
• Groups
• Roles
13
- 14. 14© 2011 IBM Corporation
6. #{id:mycontrol}
• Used if you want to know what the id of the field will be at runtime
• Use this syntax to identify a specific field:
• Also works in reused controls
14
clientsidereferences.xsp
- 15. 15© 2011 IBM Corporation
7. Calling SSJS in CSJS
• If you want to pass server side data to the client side as the page loads you
can use:
#{javascript:myfunction()}
• Returns the result of “myfunction” at runtime inside your CSJS
15
clientsidereferences.xsp
- 16. 16© 2011 IBM Corporation
• A free download from OpenNTF:
http://extlib.openntf.org/
• Provides a whole bunch of extra controls for your
XPages
• Just needs a simple install on the server to enable to
extra controls
16
8. Extension Library
- 17. 17© 2011 IBM Corporation
9. Localisation
• Easy to do
• Turn it on
• Pick which languages you want to support
• Edit the translation files
• You’re done. ;o)
17
- 18. 18
• When you add the custom control to an XPage, the Custom Properties tab of
the custom control contains the list of all of the different properties which you
can set
© 2011 IBM Corporation
10. Custom Properties
• It’s very easy to pass data around different
custom controls
• In the Custom Control properties go to the
Property Definition section
• Add a new property for each setting
• Can be any data type (e.g. String, Boolean,
Document data etc)
• Can have a default value if the property is not
set when the custom control is used
18
- 19. 19© 2011 IBM Corporation
11. Using Java classes
• Great for network operations and other pre-rolled Java functionality
• Create a “lib” folder using the package explorer
• Import your .jar file
• Refer to the full package structure or use “importPackage”
importPackage(com.xpagesblast.demo);
var text = getComponent("inputtext").getValue();
var speaker:SaySomething = new SaySomething(text);
getComponent("out").setValue(speaker.whatDoYouSay());
19
java.xsp
- 20. 20© 2011 IBM Corporation
12. Using an XPage as a servlet
• If you want to get the memory resident benefits of an XPage but don’t want to
return HTML then...
• Set the rendered property to False
• In afterRenderResponse event return required data:
try{
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
response.setContentType("text/plain");
writer.write("Hello World");
writer.endDocument();
facesContext.responseComplete();
writer.close(); //Leave this line out in 8.5.2
}catch(e){
_dump(e);
}
20
servlet.xsp
- 21. 21© 2011 IBM Corporation
13. IgnoreRequestParams
• Control individual document bindings on a single XPage
• In All Properties > Data > Data > dominoDocument, set ignoreRequestParams
to false
• Then whatever default action you have defined for the document data binding
will take precedence over the URL Parameters
• Useful for blog comments
21
requestparams.xsp
- 22. 22© 2011 IBM Corporation
Debugging
• Because although we never create bugs, sometimes more information is useful
22
- 23. 23© 2011 IBM Corporation
14. Configure Firewall
• A lot of local firewalls block ports on the local machine
• You’re basically running a local IBM® Websphere® server on a port somewhere
in the 30,000+ range
• You will never see an error so it’s difficult to debug
• Either disable the firewall or work out a rule which allows the server to run
23
- 24. 24© 2011 IBM Corporation
15. Turn on debugging
• In the Application properties, check the “Display XPages Runtime
Error Page” box.
• Then when there is an error in your code you’ll get a more useful
message
24
- 25. 25© 2011 IBM Corporation 25
Error Code Most Likely Cause
500 There’s an error in your code. Idiot ;-)
404 A typo in your URL. Remember the XPage name
is case sensitive
403 Forbidden error, the signing ID doesn’t have
rights to run XPages
302 Shows up a lot in server logs. It’s a redirection
and can be ignored.
16. Common Error Messages
- 26. 26© 2011 IBM Corporation
17. Use OpenLog
• Download OpenLog from OpenNTF
http://www.openntf.org/projects/pmt.nsf/ProjectLookup/OpenLog
• Download TaskJam (which has the script library in) from OpenNTF
• At the top of your SSJS
import OpenLogXPages
• Implement using
log.logEvent("Clearing the Cache", SEVERITY_LOW,
"serverSide", "resetApplicationScope", null);
• or
log.logError(“There was an error”, SEVERITY_HIGH,
“Error Message”, “Error Number”, “Location”, “Method”,
“Error Line”, document);
26
- 27. 27© 2011 IBM Corporation
18. Use Firebug
• The single most important debugging tool for XPages
• Lets you inspect HTML, CSS and CSJS
• Network operations and AJAX requests
• Download from Tools in Firefox or
http://getfirebug.com
• In CSJS use
dojo.console(“message”);
27
- 28. 28© 2011 IBM Corporation
User Interface
• Because even though we’re programmers, the UI is important
28
- 29. 29© 2011 IBM Corporation
19. Themes & Global Config
• Want to set something once and have it used everywhere, use Themes
• Can set; stylesheets, classes on elements or pick a skin dynamically using
simple XML, for example:
<theme>
<resource>
<content-type>text/css</content-type>
<href>custom.css</href>
</resource>
<control>
<name>InputField.RichText</name>
<property mode="concat">
<name>styleClass</name>
<value>domino-richtext
xspInputFieldRichText</value>
</property>
</control>
</theme>
29
- 30. 30© 2011 IBM Corporation
• OneUI - http://tinyurl.com/xpboneui
• Download “XPages framework” from OpenNTF
• Or use the OneUI control in the Extension Library
• Blueprint - http://tinyurl.com/xpbblueprint
• 960 Grid - http://tinyurl.com/xpb960grid
• Doesn’t matter which one, just USE ONE!!!!!
30
20. Use a CSS Framework
- 31. 31© 2011 IBM Corporation
XPages in Notes Client
• XPiNC
31
- 32. 32© 2011 IBM Corporation
• If manually building URLs for the Notes Client
• In 8.5.1 you HAVE TO add the SessionID parameter:
&SessionID=tclk48931240
• Error 503 with no other explanation if you don’t add it
• It’s been fixed in 8.5.2
32
21. Use &SessionID
- 33. 33© 2011 IBM Corporation
22. View Page Source
• Toolbar button only available if Designer installed
• Shows the source HTML of XPages in Notes client
• Useful because the HTML in the Notes Client is not always the same as in a
web browser
33
- 34. 34© 2011 IBM Corporation
23. View Logs in Notes Client
• From menu
• Help, Support, View Trace
• Where the print statement output from SSJS is displayed
• SSJS output only, CSJS output is not visible in XPiNC
34
- 35. 35© 2011 IBM Corporation
24. Difference in URLs
• If you manually build URLs be aware that there are different structures
between the Notes Client and the web browser:
• Web Browser
/directory/XPagesBlast.nsf/test.xsp
• Notes Client
/xsp/ServerName!!directory/XPagesBlast.nsf/test.xsp
35
- 37. 37© 2011 IBM Corporation
25. Enable parseOnLoad
• If you have Dojo widgets on your XPage then you should set this to true, to
have them automatically initialize
• Unless you want to manually initialise Dojo Elements yourself using Javascript
37
- 38. 38© 2011 IBM Corporation
26. Dialog box
• If you want to interact with the server from inside your dialog box. You have to
work around a “feature”.
• Best option is to use Jeremy Hodge’s approach: http://tinyurl.com/xpbdialog
• Include CSJS Library in your XPage, then enable dojoParseOnLoad and
dojoTheme
“feature” = BUG
38
dialog.xsp
- 39. 39© 2011 IBM Corporation
27. Dojo Ajax Request
• Writing your own Ajax can still be useful, simply use the xhr API:
39
ajax.xsp
- 40. 40© 2011 IBM Corporation
28. Charting
• dojox.charting offers a huge array of charting options
• For a simple pie chart
• import the basic modules
• add the data (formatted as JSON)
• add CSJS to initialize the chart
• No flash required
• offers animation
• Tooltips
• Legends
40
chart.xsp
- 41. 41© 2011 IBM Corporation
29. How to show images
• Add Dojo resource:
• dojox.image.Lightbox
• Add Stylesheet
• /.ibmxspres/dojoroot/dojox/image/resources/Lightbox.css
• Build <a> tags with dojoType of dojox.image.Lightbox
and then enable ParseOnLoad
41
lightbox.xsp
- 42. 42© 2011 IBM Corporation
30. How to use jQuery
• Use when you want to make use of a
jQuery plugin
• Import the jQuery library into the database
design as a file resource
• Everything else works as you would
expect with jQuery
• A good example is the Full Calendar
Plugin http://arshaw.com/fullcalendar/
42
jquery.xsp
- 43. 43© 2011 IBM Corporation
Questions?
• Contact Us:
• Matt White
• matt.white@elguji.com
• twitter.com/mattwhite
• mattwhite.me
• Tim Clark
• tim_clark@uk.ibm.com
• twitter.com/timsterc
• blog.tc-soft.com
43
- 44. 44© 2011 IBM Corporation 44
Legal Disclaimer
© IBM Corporation 2011. 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.
IBM, the IBM logo, Lotus, Lotus Notes, Notes, Domino, WebSphere and Lotusphere are trademarks of International Business Machines Corporation in the United States, other countries, or both. Unyte is a trademark of
WebDialogs, Inc., in the United States, other countries, or both.
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.
Other company, product, or service names may be trademarks or service marks of others.
Other company, product, or service names may be trademarks or service marks of others.