XPages Blast - Lotusphere 2012


Published on

Matt White and Tim Clark
30 top tips for Lotus XPages in 60 minutes or less.

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

XPages Blast - Lotusphere 2012

  1. 1. © 2012 IBM CorporationBP103 IBM Lotus DominoXPages Blast!Matt White | Consultant | London Developer Co-opTim Clark | Technical Services Manager | GSXFriday, 20 January 12
  2. 2. • Consultant with• Lead Developer with• Creator of XPages101.net• IBM Champion| © 2012 IBM CorporationMatt White2Friday, 20 January 12
  3. 3. | © 2012 IBM CorporationTim Clark• Technical Services Manager for GSX• Founder of ‘The X Cast‘ podcast about XPages• 17+ years at Lotus/IBM in technical roles3Friday, 20 January 12
  4. 4. | © 2012 IBM CorporationProducts we’re using• IBM Lotus® Domino® Server 8.5.3- If we use other versions for a tip we’ll highlight it• IBM Lotus® Notes® 8.5.3• IBM Lotus® Domino Designer® 8.5.34Friday, 20 January 12
  5. 5. | © 2012 IBM CorporationAgenda• Development Tips• Configuration Tips• Client Side Tips• Server Side Tips• Extension Library Tips5Friday, 20 January 12
  6. 6. | © 2012 IBM Corporation1. Turn on Debugging• The first thing to enable when developing a new XPages application• Go to Application Properties -> XPages -> Display XPage runtime error page• Don’t forget to save the Application Properties• When you get an error you will see something like this:• Don’t forget to disable it when going live!6Friday, 20 January 12
  7. 7. | © 2012 IBM Corporation2. Error Logging - Console• You have two options to send messages to the server:print(String);_dump(object);• Both are useful in development, but bad practice in production• In Notes Client use: Help -> Support -> View Trace• Also helpful is the XPages Log File on the server: C:Program FilesIBMLotusDominodataIBM_TECHNICAL_SUPPORT• Bonus Tip: Mark Leusink has released a project to OpenNTF which will display the output of print and dumpstatements in a debug toolbar7Friday, 20 January 12
  8. 8. | © 2012 IBM Corporation3. Error Logging - OpenLog• A great solution for logging in your production applications- LotusScript- Java™- Server Side JavaScript• Free downloads from OpenNTF- http://www.openntf.org/projects/pmt.nsf/ProjectLookup/OpenLog- http://www.openntf.org/projects/pmt.nsf/ProjectLookup/TaskJam- http://www.openntf.org/projects/pmt.nsf/ProjectLookup/XPages+Help• To add Server Side JavaScript support copy OpenLogXPages script library from TaskJam• To add XPages Java support copy the class from the XPages Help application written by Paul Withers• But you can also make use of Java logging frameworks- Julian Robichaux and Mark Myers session SHOW114 has more information on this:- Write Better Java Code: Debugging, Logging, and Unit Tests8Friday, 20 January 12
  9. 9. | © 2012 IBM Corporation4. Debugging Java• You can step through Java when running XPages• First add the following lines to notes.ini on server:; Enabling Java debugJavaEnableDebug=1 JavaDebugOptions=transport=dt_socket,server=y,suspend=n,address=8000JrnlEnbld=0• Restart the server• In Designer, go to the Java Perspective• Choose Run -> Debug Configurations…• Create a new “Remote Java Application”9Friday, 20 January 12
  10. 10. | © 2012 IBM Corporation4. Debugging Java• Now you can step through your code line by line• Add a breakpoint in your Java code• First time you run the code you’ll be prompted to switch into Debug Perspective• If you get “Source Not Found” click the “Edit Source Lookup Path” button• Then Add a Java Project and locate your application from the list10Friday, 20 January 12
  11. 11. | © 2012 IBM Corporation5. Show Local Server Console• If you don’t have a local server you can still see print / _dump results• First close Notes and Domino Designer• Open a DOS command prompt and go to the Notes program directory• Type nhttp –preview• Hit return and enter password11Friday, 20 January 12
  12. 12. | © 2012 IBM Corporation6. Performance Profiling• If your XPage isn’t performing as well as you’d like, download the XPages Toolbox application from OpenNTF- http://www.openntf.org/projects/pmt.nsf/ProjectLookup/XPages%20Toolbox• It offers processor and memory profiling options• You can even identify the individual blocks of code which are taking too long to load12Friday, 20 January 12
  13. 13. | © 2012 IBM Corporation7. Source Control Enablement• With the release of 8.5.3 we can now use Apache Subversion as a source control tool• Niklas Heidloff has written two great articles:- To set up SVN: http://bit.ly/svnconfig- To use SVN: http://bit.ly/svnuse• But not limited to SVN, I use GIT which is largely considered a more modern source control system• Download the EGit For Domino Designer project from OpenNTF- http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=EGit%20for%20IBM%20Domino%20Designer• Follow the instructions for setting up GIT in Windows- (good example at http://bit.ly/gitsetup)• Using the EGit tool is then very similar to SVN• For more detail:- Declan Lynch’s session Source Control For TheIBM Lotus Domino Developer (AD102)13Friday, 20 January 12
  14. 14. | © 2012 IBM Corporation8. CGI Variables• To get at information about the current page / user / browser “facesContext” is your friend• For examplefacesContext.getExternalContext().getRequest().getRemoteAddr()returns the IP address of the current user• Thomas Gumz wrote a script library which makes it easier to access the variables.• It can be downloaded here: http://bit.ly/cgivariables• Syntax to use is:var cgi = new CGIVariables()print(cgi.REMOTE_ADDR);14Friday, 20 January 12
  15. 15. | © 2012 IBM Corporation9. Disable Theme• If you don’t want to use any IBM provided CSS then create a blank theme and apply it to the application• Even the simplest page will go from requiring 3 css files to none15Friday, 20 January 12
  16. 16. | © 2012 IBM Corporation10. Disable Dojo• If you don’t want to use Dojo in your site• It might be a static website for example or use a different JavaScript framework• Switch to Package Explorer and locate the xsp.properties file in WebContentWEB-INF and add the followingline:xsp.client.script.libraries=none• The source of the page is now:16Friday, 20 January 12
  17. 17. | © 2012 IBM Corporation11. Disable Form• Continuing the theme of removing default settings. If your page doesn’t need to interact with the server you canalso disable the supporting fields• In the XPage set the “createForm” property to false17Friday, 20 January 12
  18. 18. | © 2012 IBM Corporation12. Custom Properties• Custom controls can be more flexible and re-usable• By adding parameters, known as Custom Properties to them the same custom control can be used multipletimes in different ways• You can create as many properties as needed in the Property Definition tab18Friday, 20 January 12
  19. 19. | © 2012 IBM Corporation12. Custom Properties• To access custom properties inside the custom control use the compositeData object• When adding a custom control to the XPage the Custom Properties tab can be populated with the settings19Friday, 20 January 12
  20. 20. | © 2012 IBM Corporation13. Resource Bundles• Rather than using profile documents or reference data documents and views, resource bundles allow quickaccess to configuration settings• Create a new file with a “.properties” extension:• In your Server Side JavaScript you can then use the syntax settings.getString(“key”)20Friday, 20 January 12
  21. 21. | © 2012 IBM Corporation14. Read and Edit on Same Page• If you have multiple document bindings on the same XPage, you can control the mode of documentsindividually• Set the ignoreRequestParams property in the data settings to true and then manually set the Default Action ofthe binding to the mode desired• Remember that most containers can have data bound to them- You don’t have to set up data binding at the XPage or Custom Control level- Panels can be especially useful to bind data to21Friday, 20 January 12
  22. 22. | © 2012 IBM Corporation15. Session Timeouts• In Application Properties you can set how long the sessionScope and applicationScope variables will be kept inmemory• Make sure Session Timeout is set to longer than the Session length for authenticated users• Or make sure that you manage your sessionScope variables properly!22Friday, 20 January 12
  23. 23. | © 2012 IBM Corporation16. Access Fields in the Client• If you are generating the IDs of fields in Server Side JavaScript use:getClientId(“myfield”)• To access the field in Client Side Javascript use:“{#id:myfield}”- When the HTML for the page is generated you will see• Or you can use dojo.query to find fields using CSS classes as an identifier- To get hold of all elements on a page with a specific CSS class assigned:dojo.query(".myclass")- And that can be extended like so:dojo.query(".myclass").forEach(function(node, index, arr){//Do something with each element having selected it});23Friday, 20 January 12
  24. 24. | © 2012 IBM Corporation17. Access Fields on the Server Side• To access a field using Server Side JavaScript use:getComponent(“myfield”)• When accessing field values after clicking submit you need to know the difference between getSubmittedValueand getValue- All to do with when validation runs- The order of fields on the XPage is important• To get the value before validation has run use:getComponent(“myfield”).getSubmittedValue()• And after validation has run use:getComponent(“myfield”).getValue()24Friday, 20 January 12
  25. 25. | © 2012 IBM Corporation18. Controlling Partial Refreshes• You can write your own Client Side JavaScript to force a partial refresh of an element on the page:- XSP.partialRefreshGet("#{id:mypanel}",{params: {’$$xspsubmitvalue’: dojo.byId("#{id:inputText1}").value}});• To access the submitted value on the server side use:- context.getSubmittedValue();• Using this technique you can even chain partial refreshes together:- XSP.partialRefreshGet("#{id:mainpanel}", {params: {$$xspsubmitvalue: dojo.byId("#{id:inputText1}").value},onComplete: function () {XSP.partialRefreshGet("#{id:secondpanel}");}});25Friday, 20 January 12
  26. 26. | © 2012 IBM Corporation19. Building URLs• Although classic URLs still work, it’s best to use the XPages format URLs- They will work in the Notes Client as well as the browser- They perform better• For attachments:- http://myserver.com/mydb.nsf/xsp/.ibmmodres/domino/OpenAttachment/mydb.nsf/[UNID]/MyField/myfile.xls• For Dojo resources:- http://myserver.com/.ibmxspres/dojoroot/dojox/image/resources/Lightbox.css26Friday, 20 January 12
  27. 27. | © 2012 IBM Corporation20. Extended Application Settings• There are some settings which are hidden away in the Package Explorer view• From the Window menu, choose Open Perspective -> XPages• Switch to the Package Explorer view and locate the file:- WebContentWEB-INFxsp.properties• It has a whole lot of settings which include all of the XPages properties from the Application Settings• But you can also change other things- doctype- Extension Library settings such as which XPages should be treated as mobile pages- Dojo Version- and many more• It’s worth investigating all the options27Friday, 20 January 12
  28. 28. | © 2012 IBM Corporation21. Dojo Widgets• To use a Dojo Widget:- Find the widget you want to use on http://dojotoolkit.org- Add the Dojo Resource to the XPage• Now we need to tell the XPage to enable parseOnLoad and load the dojoTheme28Friday, 20 January 12
  29. 29. | © 2012 IBM Corporation21. Dojo Widgets• Next you add the control and set its Dojo Type• When we preview the XPage the Dojo Widget will be automatically initialized29Friday, 20 January 12
  30. 30. | © 2012 IBM Corporation22. XPages as Agents• If you want to output non HTML data from your XPage it’s a very simple process- Also known as XAgents or Headless XPages• Set your XPage rendered property to false• In the afterRenderResponse event use code in this format30Friday, 20 January 12
  31. 31. | © 2012 IBM Corporation23. Export to Excel• Uses the XAgents technique• Change the content type to “application/vnd.ms-excel”• Output the Excel file as XML (works only with Excel 2003 or later)31Friday, 20 January 12
  32. 32. | © 2012 IBM Corporation24. SSJS and JSON• There are built in functions to work with JSON in Server Side JavaScript• To test a string to see if it is valid JSON, use- isJson(mystring)• To parse a JSON string use- fromJson(mystring)• To convert an object to JSON use- toJson(myobject)32Friday, 20 January 12
  33. 33. | © 2012 IBM Corporation25. Multiple NSFs• You are not restricted to using data from the same database that the XPage is in.• You can compute the database name and the Form or View name in your data binding• To save more manual work- create the XPage in the database that contains the data- copy the XPage to the place it will run once binding is set up- Now change the binding to point to the database where the data is33Friday, 20 January 12
  34. 34. | © 2012 IBM Corporation26. Relational Databases• Along the same lines it has never been easier to use non Domino data in your applications• JDBC can be set up easily in your application without using Extension Library• Copy the JDBC Driver .jar file to- ..lotusdominoxspsharedlib• Now create a Java class in your application to connect to the database34Friday, 20 January 12
  35. 35. | © 2012 IBM Corporation26. Relational Databases• Now inside a repeat control on our XPage we can access the relational database35Friday, 20 January 12
  36. 36. | © 2012 IBM Corporation27. Navigation Rules• If you have a workflow application or the flow of pages in your application changes then consider userNavigation Rules• In the XPage create different rules and give them a name• Now in your buttons you can simply decide on the rule to use in the action property when they are clicked• In this case the action is stored in a viewScope variable which is calculated elsewhere36Friday, 20 January 12
  37. 37. | © 2012 IBM Corporation28. Extension Library - Widgets• The Extension Library is a free download from OpenNTF at http://extlib.openntf.org• At the simplest level it provides > 60 controls which can be dragged onto your XPages to cover everything fromDialogs and Tooltips to JDBC connections• To use, make sure the Extension Library is installed on the server and in Domino Designer• Drag the control onto the XPage• Save and deploy, simple as that- See also my other session BP115 - Deploying and Managing Your XPages Applications- We talk about the “simple as that” for an hour, but that’s for admins!• As of December 2011 there is also the choice to use Upgrade Pack 1• This is the officially supported version of the Extension Library- You just need to decide which best suits your needs37Friday, 20 January 12
  38. 38. | © 2012 IBM Corporation29. Extension Library - JDBC• Much easier to implement than the manual approach• Still need to copy the relevant jar file into your file system but to a different location:..dominodatadominoworkspaceapplicationseclipseplugins• Then you need to create a .jdbc file which defines the connection• Now in your XPage you can set up a jdbcQuery data source in the same way you would a view or document• Set the connection name to the name of the .jdbc file you just created and provide the sqlQuery38Friday, 20 January 12
  39. 39. • In your view control adding a column name is simple• Once you’ve added columns to the view, it just works- You can even add sorting to columns and the query will be adjusted automatically to reflect what column theuser clicks on• One other interesting thing is the new @Formulas available:- @JdbcDbColumn- @JdbcUpdate| © 2012 IBM Corporation29. Extension Library - JDBC39Friday, 20 January 12
  40. 40. | © 2012 IBM Corporation30. Extension Library - Mobile Controls• The middle ground between no mobile interface and a native app is a mobile web design• Built into Extension Library they are very easy to use• Drag on a SinglePageOutline control and then add content inside• You can add forms and views and static content• Works well out of the box for iOS and Android- Blackberry needs a little more work40Screenshots courtesy of Vigilus LLCFriday, 20 January 12
  41. 41. | © 2012 IBM CorporationRelated Sessions• Session BP115: Deploying and Managing Your IBM Lotus Domino XPages Applications- Warren Elsmore and Matt White• Session AD102: Source Control For The IBM Lotus Domino Developer- Declan Lynch• Session AD104: IBM Lotus Domino XPages Made Social- Philippe Riand• Session AD106: IBM Lotus Domino XPages anywhere - Write them once, See them Everywhere- Stephan Wissel• Session AD107: IBM Lotus Domino XPages Meets Enterprise Data - Relational++- Andrejus Chaliapinas• Session AD108: The Grand Tour of IBM Lotus Notes and Domino 8.5.3 Upgrade Pack 1s XPages Capabilities- Martin Donnelly• Session AD109: Ready, Set, Go! How IBM Lotus Domino XPages Became Mobile- Eamon Muldoon• Session AD110: IBM Lotus Domino XPages Go Zoom!- Darin Egan• Session AD111: The X Path: Practical guide to taking your IBM Lotus Notes applications to Domino XPages- Stephan Wissel41Friday, 20 January 12
  42. 42. | © 2012 IBM CorporationQuestions?• Matt White- matthew.white@fclonline.com- @mattwhite- mattwhite.me• Tim Clark- tim@tc-soft.com- @timsterc- blog.tc-soft.com42Friday, 20 January 12
  43. 43. | © 2012 IBM Corporation43Legal disclaimer© IBM Corporation 2012. 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 withoutwarranty 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 arisingout 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 suppliersor 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 atany 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, norshall 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, Quickr, Sametime, WebSphere, UC2, PartnerWorld 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.Friday, 20 January 12