Tag Archive: JavaScript

Getting the Correct Syntax for JavaScript in XPages

I was recently working on a project where my code was injecting XPage elements onto the page at runtime.  To do that, you need to know a lot of syntax.  Syntax that isn’t in the help file, or blogged about, or easily findable.  Sure, there’s this, but that isn’t exactly reader-friendly, nor are there examples of how to use the elements.  Just because you know you’re using “XspInputText”, doesn’t mean you know how to use it.  What’s the syntax for adding an attribute, for example?  Or maybe you know the syntax structure, but need to know what the parameter looks like in the code.

Designer Data Panel for Date Field For example, you want to add a Date field with certain parameters set.  You know how to set them in Designer in the data panel, but how do you set those parameters programmatically in JavaScript?

Thankfully, Toby Samples showed me a cheat to find out.  Create a dummy XPage, add your element and do whatever it is you want to do, i.e. set the parameters for your date field.  Save the page.  In Designer, go to Package Explorer and your nsf.  Expand the Local folder and then the xsp folder.  There you’ll see all of your custom controls and XPages with a .java extension.  Double-click on the XPage.java file.  It will open and there you’ll see the Java code used to generate that XPage, including your element and how the parameters were set programmatically.  This can be really useful when you’re adding something like an attribute via JavaScript and you can’t find any examples of HOW to add an attribute (or class or value binding or any other property).

Example, if you set the above “display format” to “Date and Time” in the picker, how is that set programmatically?


With the parameter “both”.  Good luck figuring that out on your own.

File under: “Things you may have already known, but I didn’t, and I share it just in case you didn’t either” AND “Blog post titles I struggled with actually explaining what the post was about without actually typing the post in the title”

Review: If Hemingway Wrote Javascript

If Hemingway Wrote JavaScript
Angus Croll
No Starch Press

I’m not going to lie to you and say that you’ll learn JavaScript from this book.  It is, however, incredibly entertaining.  The author takes 25 “literary luminaries” and presents 5 different JavaScript assignments as though completed by the luminaries.  Also included are four poems, such as “The Variable” ‘by’ Edgar Allen Poe.

The assignments include things like writing a function to show the first n numbers in the Fibonacci sequence and writing a chainable function to accept one word per call, but play back all the previously passed in words in order. The authors include Hemingway (of course), Shakespeare, Kafka, JK Rowling, and more.

It’s a very clever book, very well written. Showing different authors tackling the same JavaScript assignments is just genius. Hemingway, for example has zero comments in his code. Shakespeare has more comments than code, and they’re of course written in iambic pentameter.

My only complaint is that the Kindle version seems to be images, rather than text, and some of the images didn’t transfer well to eBook format. Get yourself the paperback version.

Obtained From: Book store
Payment: $13

Review: Speaking JavaScript

Book: Speaking JavaScript

By: Dr Axel Rauschmayer

Publisher: O’Reilly Publishing

Thorough book on JavaScript from the very basic to the more advanced with lots of tips and example code along the way.


  • i. JavaScript Quick Start
  • Basic JavaScript
  • ii. Background
  • Why JavaScript
  • The Nature of JavaScript
  • How JavaScript was Created
  • Standardization: ECMAScript
  • Historical JavaScript Milestones
  • iii. JavaScript in Depth
  • JavaScript’s Syntax
  • Values
  • Operators
  • Booleans
  • Numbers
  • Strings
  • Statements
  • Exception Handling
  • Functions
  • Variables: Scopes, Environments, and Closures
  • Objects and Inheritance
  • Arrays
  • Regular Expressions
  • Dates
  • Math
  • JSON
  • Standard Global Variables
  • Unicode and JavaScript
  • New in ECMAScript 5
  • iv. Tips, Tools, and Libraries
  • A Meta Code Style Guide
  • Language Mechanisms for Debugging
  • Subclassing Built-Ins
  • JSDoc: Generating API Documentation
  • Libraries
  • Module Systems and Package Managers
  • More Tools
  • What To Do Next

This is a very thorough book.  If you’ve had no experience at all with JavaScript, read the first section:  JavaScript Quick Start.  This will give you the basics that you need to get started with JavaScript.  If you’ve been using JavaScript already, then skip ahead.  Personally, I could do without the “Background” section, but I’m sure some readers will find it useful.  Also, I feel a “Why JavaScript” section is a bit useless as I’m probably already convinced of the usage of JavaScript if I’m reading this book, but hey, maybe you can read this section and convince your friends to use JavaScript.  So jumping into the more useful (to me) section of the book, “JavaScript In Depth”:  I liked the included sections for the various categories including:  best practices, tips and tricks, “don’t be clever”, controversial rules, and pitfalls.  Not only are more advanced topics of JavaScript covered, but also practical usage of JavaScript (and how to avoid trouble).  Use cases are included, as well as my favorite “format” for demonstrating code including: “bad”, “better”, and “best” examples.

Obtained From: Publisher
Payment: Free

Article: This is a stickUp

No, I’m not trying to rob you.  This is a handy little bit of code to keep your tool bars at the top.

While we would all love to create slick applications with a sleek UI (read: not a lot of stuff on the page), most of us are creating enterprise applications that often require lengthy forms with field after field after field. There are of course many solutions to attempt to deal with the issue. You can break the form up into tabs (don’t get me started on this, tabs are another article), or sections, or maybe a wizard. You can just give up and have a lengthy form, but then what do you do when the user wants to save? Make them scroll all the way to the top or the bottom of the page?

Read the full article…

Article: Too Many If Statements Time To Switch It Up

A quick JavaScript (and even LotusScript) tip this month for SocialBizUg.org.

This may be obvious to some of you, but it’s always good to cover the basics in case you missed it. If statements. IF your code (Haha! See what I did there?) has a lot of if statements and else if statements, in a never-ending string of impossible-to-follow conditions, THEN you should consider switching it up to a SWITCH statement.

Read More…

Older posts «