Friday, October 28, 2011

Be careful with empty CKEditor rich text fields


The CKEditor is very handy in XPages since it saves the content as MIME which can be processed as such in other places in your application. However you should be aware of how it operates so you can code around its behavior.

In 8.5.3 the CKEditor for rich text controls has been updated.

1. If you never enter any information into the field, then the field is a text field even if the document has been saved.

2. If you enter a single space and save the document, then the field is a MIME object and remains so even if you remove the content and re-save the document.

SOLUTION:

Use something similar to the code below to discover if the field is actually MIME or just plain empty text:


if(doc.getFirstItem("aRichTextField").getType()==Item.MIME_PART){
x=doc.getMIMEEntity("aRichTextField").getContentAsText();
}else{
x="";
}


NOTE: I have already upgraded everything to 8.5.3 so I cannot accurately verify but I believe this was not the case in 8.5.2 because after upgrading some existing/working suddenly stopped working and this was the cause.

If anyone knows differently about 8.5.2, please let me know.