A Legacy Notes Developer's journey into madness.

It’s Getting Better All The Time

Devin Olson  September 25 2013 05:29:25 AM

Wherein I babble about XML Namespaces even though they are not the point of this post



So I was working this morning on a custom control, and I wanted to create a NEW custom control using content from the control I was working on.  

Specifically, I wanted to COPY a Form Table control from one CC to another CC.  

No problem, right?   I simply selected the control I wanted while in the Design pane, did a quick CTRL+C, opened the target CC, and did a CTRL+V.   The control pasted in just fine.  


Except that it didn't.



The control pasted in, but it looked NOTHING like it was supposed to.  It was seriously jacked up.   (BTW - all the thumbnail images in this post are linked to full-sized images, just click on the one you are interested in to see the full-sized image).

So there I was, looking at this screwed up control and quietly muttering unrepeatables under my breath.  I switched to the Source pane and took a look.  (Side Note: once you've been actively developing XPages for a while you may, as i have, "default" to the Source pane.  This is normal and healthy and a sign of your growing maturity, confidence, and comfort as an XPages developer.)

In the Source pane a red decorator was showing, and a mouse-over caused the problem pop-up tip to display the problem:  

The prefix "xe" for element "xe:formTable" is not bound.


A year ago (shortly after I began REAL development in XPages) I would have been completely lost.  Six months ago I wouldn't have known what the problem was, but I would have at least known where to look and who to ask.  Today I read this and just knew the cause (and more importantly, the solution).  The issue is not really that big of a deal, the problem with the issue is that the explanation is kind of stupid and misleading.   So allow me to translate.  When the eclipse designer tells you The prefix "xe" for element "xe:formTable" is not bound, it really means:

I don't know what the prefix "xe" means, did you forget to declare a Namespace?


The problem here is that I had not added appropriate Namespace information to my control.  XML Namespaces help developers to avoid element name conflicts.  We use them in conjunction with an element prefix to associate a specific Namespace with the control.  My code opened a formTable element (line 4 in the image) with the code:
<xe:formTable id="formTable1">

The "xe:" at the beginning of the element tag is the prefix, and essentially tells the browser (or in this case the eclipse designer) to apply the associated Namespace to the remainder of element (the "formTable" part).  Eclipse doesn't know how to deal with the element because I had not associated a Namespace with the prefix.  I quickly fixed this by adding the Namespace declaration to the containing view element (and also a Namespace for the "xc" tag while I was at it):
xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom"


Once I added the Namespace information the problem indicator when away, and the control appeared the way it was supposed to in the Design pane.  

What is the lesson learned here?  I don't think there is one. The point of this post has nothing to do with XML Namespaces.  

The point of this post is that I KNEW both the cause and solution of the problem, without having to do any research or JFGI or anything.  I can't tell you where or when I picked up my understanding of XML Namespaces and prefixes -I honestly don't remember.   I did a bunch of stuff with XML (even wrote some XML for Domino Developers courses) back in 2001, but would not consider myself an "expert" by any means.  

The cool thing is that I knew the answer simply because I've been doing XPages development regularly for quite some time now.  Somewhere along the line over the last year of work I learned this information and filed it away for a time it would be needed.  

Today when I JUST KNEW the answer I was so surprised about it that I needed to share.  Keep developing, and you will also start to JUST KNOW the answers.  Not all of them, not all of the time.  But every once in a while you will surprise yourself.

THAT is the point of this post.  


-Devin
Comments
No Comments Found

Discussion for this entry is now closed.