New release of Bildr

I have submitted a new release of my Bildr project on OpenNTF.

In case you are unaware of this project, the application allows you to quickly upload and share images within your network. Images are scaled and you can group them in albums.

The idea behind this app was to have a real case scenario to learn XPages, and frankly the learning experience has gone beyond expectations. I also have to thank Mark Leusink for his contributions.

This release fixes the problems I had with Google Maps. Although the solution is not ideal ( I would like to group markers) due to lack of time I am now satisfied with it.

I also used DDE and it’s search capabilities to remove redundant design elements.

Below you can see some screenshots of the application:

 

 

 

Download: Twitter Bootstrap in Domino Blog

Have you sometimes the feeling that in case you know too much it may be used against you?

Recently I posted how to include Twitter Bootstrap in the IBM Domino Blog template.  Some time ago I blogged frequently about administrating that same Blog application.

From my Twitter Bootstrap post I received some questions from people for help so the easiest way to assist would be to make an example application available for downloading. The NSF contains all the documents that are needed to utilize (or get started with) Twitter Bootstrap within a Domino blog.

I also added some sample blog posts and link documents that refer to websites for education and resources (themes).

Download

Here you can download the example:  link.

Instructions

  • Extract the file.
  • Sign the application with proper ID.
  • Apply proper ACL settings.
  • Open the Configuration document and apply correct settings.
  • Launch the application in browser.
    • In case the HTML layout is rendered properly I suggest to save ALL documents under HTML Templates section.

Good luck!

Screenshots

Homepage
Document
A document list (~ Notes view)
Mobile display

Zähme den Tiger – Java entwicklung in Notes & Domino

Introduction

Today I read this presentation by Bernd Hort held at EntwicklerCamp 2012. Judging fromthe different presentations this sounds like a excellent conference!

This was a nice opportunity to rehearse my German. In case your German is not so good I recommend to listen to a couple of albums of these guys and you will do just fine =)

The presentation can be divided into 2 parts:

  • A general introduction to the Java language.
  • Java in Notes & Domino in details.

Introduction Java language

A nice introduction to the language. More details I found in the jumpstart Eating the elephant.

Java in Lotus Notes & Domino

This section is divided into:

  • Applets
  • Agents
  • Servlets
  • Standalone applications
  • XPages
  • Plugins
  • Other

Applets

If you are interested in writing applets The View has published plenty of articles about this.

Agents

  • Similar to LotusScript agents.
  • Only back-end documents.
  • Notes:
    • Scheduled agents.
  • Web:
    • WebQueryOpen / WebQuerySave.

Also here check The View knowledge database to find articles on Java agents.

Servlets

Also a walk through memory lane…

  • Advantage in comparison to Java agents is than once the servlet is initiated the second call is much faster.

Standalone applications

Read: Java access to the Domino Objects (DeveloperWorks)

XPages

Lots of examples of Java with XPages here (setup folder structure, import jar files, notes.ini variables, writing Java classes from Package explorer…)

Other

  • Web services
  • OSGI tasklets ( Java based server tasks)

Summary

Another great presentation on Java in Notes & Domino. However most parts are also discovered in the other presentations I described earlier. Nevertheless recommended to read (if you like German).

AD104 Intro to Managed Beans (Russel Maher, MWLUG 2012)

Introduction

This presentation was not on my initial ‘to-study list’ so I will add it there. The presentation was held by Russel Maher at the MWLUG 2012.

Not surprisingly this presentation has quiet some familiarities with the presentation Improving XPages Application Performance with Managed Beans (Russell Maher, The View Advanced Xpages 2012).

Same presenter, similar topic.

Beginnings

Why use beans, managed beans and Java in your XPage projects:

  • Makes your applications run faster.
  • Reduces app maintenance efforts.–
  • Improves reliability.
  • Makes you a stronger developer.
  • Enhances your professional skills.

Complexity

Arguments why objects are sometimes better:

  • A user can have more metadata than just their name and roles.
  • A “document” might actually be comprised of multiple records.
  • An “environment” might be comprised of multiple databases.

Reduce complexity by embracing complexity:

  • Managing a large number of scoped variables in your app.
  • Dynamic visibility of scoped variables.
  • Progressive disclosure of scoped variables.

Requirements of a Managed:

  • Java class.
  • No-argument constructor.
  • Expose properties/fields through getters/setters.
  • Serializable.

Persistance

Sometimes data needs to stick around for a while:

  • “Data” can be a number or a complex object.
    • Session scoped.
    • A session is generally there until the user shuts down the browser.

Persistence allows you to know what the user did “before”

  • They saved a document.
  • They saved as draft/complete.

Beans can be scoped to application, session, view, request or none.

Managed Properties

Sharing data between beans:

  • Representing complex objects typically results in a “logical normalization” of data.
    • You generally will include all of the data about an object with that object.
    • You generally will not duplicate that data into other objects.
  • You want to pass data from one bean to another.
  • You need to read some existing data in another bean from your current bean.

Options for sharing data across beans:

  • Using variable resolvers:
    • Accessing other beans through the session map.
    • See: Persistence
  • Using managed properties:
    • One bean is a property of another bean.
    • Configured in faces-config.xml.
    • Object declared within “container” bean.
    • At run time the managed property is “injected” into the container bean.

Defined in Faces-config.xml:

 

How to use the managed property:

 

 

Managed property setter:

 

Tips

Use proper scopes and load order

  • Use the longest scope you need that will work:
    • Issues with viewScope serialization?
      • -> Use session scope.
    • Only need the bean for a single request?
      • -> Request scope.
    • Don’t need the bean to persist at all?
      • -> None scope.
  • Every bean must be called before it can be used.
    • If you try to inject Bean B into Bean as a managed property and Bean A has not been instantiated yet…you got problems.
    • If Bean A errors out but is a managed property of Bean B…you got problems.

Use Java UUID to get unique numbers

  • Designed to give universally unique numbers.
  • Beats inventing your own mechanism if all you need is a unique number.

 

 

Summary

Another great introduction on managed beans, especially if you didn’t get a hold on the Improving XPages Application Performance with Managed Beans from The View conference.

I haven’t taken a look at the example database, which was demonstrated during this presentation but that is something I will surely will when returning back to the office on Monday.

That’s it for this week. It has been a great 5 days of Java in Xpages. For next Monday I schedule ‘Zähme den Tiger – Java-Entwicklung in Notes und Domino‘. Looking forward to rehearse my German skills!

AD102 – Caffeinate your XPages with Java (Jeremy Hodge, MWLUG 2012)

Time for another step in my road ahead. This time I have studied Jeremy Hodge’s presentation at MWLUG 2012. As promised Jeremy will demonstrate how to inject Java in XPages application.

Getting started with Java in Designer & XPages

Java Design element in DDE 8.5.3:

Roll out your own project structure via Package Explorer Eclipse view:

You can customize your Java perspective:

  • Should reside in the WebContent folder.

What is a package?

  • A way to organize source code modules by using a namespace to prevent class collisions.
  • Provides some access control on what is accessible between classes.

Package

In the Package Explorer right click your source folder, select New > Package.

Naming conventions for a Package:

  • Everything lower-case.
  • Reverse domain name; Project . Sub-Project
    • e.g. com.zetaone.mwlug.ad102

Java class

In the Package Explorer right click the Package, select New > Class.

Naming conventions for a Java class:

  • UpperCamelCase class name.

The new empty class is created & opened in the workspace.

 

Access levels to methods:

  • Public:
    • Any other class, in any package can access the method or member field.
  • Private:
    • Can only be accessed within the same class.
  • Protected:
    • Can be access by the current class, sub-classes, or any other class in the same package.
  • Blank:
    • Can be access by the current class, and any other class in the package, but not any sub-classes (unless they are in the same package).

Access Java packages via import e.g. import java.util.Date

Managed beans

Bean

Nothing more than a simple Java class.

Managed bean

A Java Class that conforms to a specific set of requirements so that the XPages runtime can create / discard / etcetera our beans for us when we want to use them. In other words it manages our beans for us.

Three things required for a managed bean:

  1. Argument-less constructor.
  2. Serializable.
  3. Uses Getters / Setters to retrieve / store information.

Constructor

A method:

  • With no return type.
  • Has the same name as the class itself.
  • Does not take any arguments.

public class HelloWorld {

public HelloWorld(/*SEE NO ARGUMENTS HERE*/) {
// Do initialization here if you need to…
}
}

Serialization

The process by which an instance of a class is stored in a form that can be written to disk, the network, etcetera and then converted back into a full in-memory instance (save/restore state).

In most cases basic classes can be serialized by implementing Serializable and adding serialVersionUID.

 

implements Serializable

This is called an interface. An interface is a predefined set of procedures for transmitting data between different objects.

Serializable defines 2 Methods:

  • writeObject
  • readObject

serialVersionUID tracks what version of this class is so that objects serialized with one version are not de-serialized into a different, incompatible version.

private static final long serialVersionUID = 1L;

  • static:
    • The declaration belongs to the class, not the instance, and all instances of the class share the same serialVersionUID instance (not value) and it is stored with the class.
  • final:
    • Once it is assigned, it can’t be assigned again – Must be assigned when its declared, or in the constructor.
  • 1L:
    • The “L” makes the 1 and long integer (64bit), rather than the default 32bit integer.

Getters / Setters

Use getters / setters to retrieve or set values inside your class instance.

Declaring a managed bean

  • Modify faces-config.xml located in WebContent/WEB-INF.
  • Set the Name, Class, and Scope of the Managed bean.

Usage within Xpages

Use the managed-bean-name to reference the class. Expression Language (EL) converts “helloWorld” to getHelloWorld() and “helloWorldDateTime” to getHelloWorldDateTime() when reading the value from the bean.

 

But we also defined a setHelloWorld() method. How do we use that to store a value back into our instance?

  • If the component that you bind to your class member is read/write (ie a text box), it will call the setter to update the new value automatically. You don’t have to do anything else!

EXCEPT: Since we are now storing data in the instance that we want to stick around between requests, we need to update our faces-config.xml to set a different managed-bean-scope, such as view.

 

 

 

 

 

 

 

 

 

 

 

 

 

After refresh:

 

Reading & Writing Notes Data in Java

Similarity between reading / writing Notes data in LotusScript, Server-Side JavaScript and Java.

 

Tips, Tricks, & Gotchas

Compare objects

If you want to compare two objects, the objects need to have a .equals() or .compareTo() method.

If (string1 == string2) {
// This is (almost) never true
}

For objects, the == checks to see if the left and right objects are the same object (same address in memory), not if the string has the same content.

If (string1.equals(string2)) {
// Now we’re cooking…
}

There is also an .equalsIgnoreCase()

Getting SSJS Common Instances in Java

SSJS is a scripting language, so several objects are pre-defined and immediately available to you (ie database, session, sessionAsSigner).

In Java, you need to get the variable resolver, and resolve those variables to get at those objects.

 

There is a set of helper functions in a JSFUtil class that Jeremy as posted on OpenNTF In a project called mypic (http://xpag.es/?mypic)

Security

At some point you are likely to want to use a 3rd party class. You’ll put the JAR file in your NSF, add it to the build path, and you’ll think life is grand, until.

NoClassDefFoundError

Two main reasons you will get this error

  • Unresolved Dependencies.
    • You didn’t add all the JARs you needed to.
  • The Security Manager is telling you to take a hike, it doesn’t trust that “type” of code in an NSF.

Edit your $INSTALL\jvm\lib\security\java.policy file and grant all permissions to all code.

Serialization, Recycle, and Notes objects

You can not serialize lotus.domino.* classes, ever, AND they WILL get recycled on you – so having them as class members is dangerous!

Biggest reason is recycle(). Recycling is unique to the Notes/Domino objects because the java objects are a wrapper around the C API objects.

Two ways to get around it.

  1. Only deal with the Notes objects when you have to “go to disk” – i.e. load document, save document, read from a view, etc.
    1. Do it all locally within your method, store the contents you read in class members, then discard all Notes objects immediately.
  2. Mark your Notes objects as “transient”, then implement a method to return the cached object.
    1. In that method, check to see if the object is valid, and if so, return it, otherwise, get it again.

Recycle

General rules:

  • You should recycle anything you open when you no longer use it (but one-off documents or databases won’t hurt you too bad) … improves scalability.
  • Anything you open in a loop, recycle before the next loop – or you’re prone to crash w/ “Out of Memory” errors – DON’T Recycle a session, or anything you get from a resolveVariable() call

Summary

This presentation is another great step learning Java especially in the XPages environment. In the last section of the presentation, “The Fun Stuff”, Jeremy goes into detail describing an example of what you are capable of using Java in XPages. This section is a bit out of my head, right now.

I thank Jeremy for sharing the presentation! I noticed also a second presentation Jeremy held at the MWLUG “Introduction to managed beans“. I add this also to my ‘to-study’-list.