Simon's Blog

Mostly tech related stuff.

Archive for the category “XPages”

Why you should use source control (doh!)

I have been tinkering with an application on and off for a few months. The plan was to submit to openNTF at some stage.

I am spending maybe 30 minutes max every couple of weeks. Each time I finished changing it for the day I would create a new copy of the database. That way if I make a mess I can revert back to previous version (safety vs Eclipse Local History).

I wasn’t using source control, because it was only one user and what could possibly go wrong? :) right??!!

So recent sit down with the code, I had CSS misbehaving and it was pushing my repeat control all over the place. After some annoyance I finally got that working. Checking it in the client while it worked I found one of the action buttons now was broken. I was pretty sure I didn’t touch the button.

I go back to the previous release and see there is a whole load of code differences. I paste them back in. I noticed however the code in the backup appears to be out of sync in what I did the last time.

Checking back further I realized that I was working from the backup of an earlier day and had done so a few times. -_-”

So now my code is working perfectly, just in multiple different databases.

On the plus side it looks like ExtLib will do nearly everything I had coded anyway, making life easier to create my Frankensteins monster of a new database. Only this time I will be using a source control.

Databinding to an image component.

embedding image example.

The XPages image component is read only. So it is great for reading an image from your document/URL, but if you do any kind of image editing then it becomes a pain to save it back. Or if you need to pull an image from another location (ie. avoid link jacking) it doesn’t have an easy way to do this.

The easy way around it is to convert the image to a text resource instead.You can pull an image, convert to text and store with ease, using Java. The image component can then read the value directly.

Example XPage code: 

 <?xml version="1.0" encoding="UTF-8"?>
 <xp:view xmlns:xp="http://www.ibm.com/xsp/core">
 <xp:image id="image1">
 <xp:this.url>
 <![CDATA[#{javascript:
var urlString = "http://sodohertydotcom.files.wordpress.com/2012/01/simondemoing.png";
var url = new java.net.URL(urlString);
var bi = javax.imageio.ImageIO.read(url);
var baos = new java.io.ByteArrayOutputStream();
javax.imageio.ImageIO.write(bi, "png", baos);
var byteArray = baos.toByteArray();
var base64Bytes = com.sun.org.apache.xml.internal.security.utils.Base64.encode(byteArray);
// Save this variable to your text field.
var answer = "data:image/png;base64," + base64Bytes;
return answer;}]]>
 </xp:this.url>
 </xp:image>
 </xp:view>

Limitation: 

Due to a bug in Java it is not possible to save the favicon.ico image from a web site this way.

dBar makes life so much more easy.

A big thanks to Mark for his awesome XPages debug tool bar. I have banged my head against the wall trying to solve an issue in my application. 2 minutes after installing the debug tool bar I solved it!

Post Navigation

Follow

Get every new post delivered to your Inbox.

Join 137 other followers