bb.command.load doesn't work with e:fragment

When searching through the BDN forum for e:fragment you will find multiple complaints about javascript errors when using bb.command.load, or the declarive c:load equivalent, in combination with the <e:fragment /> as the root node of the requested file. Hopefully this blog post will clearify this issue.

In essence, the <e:fragment /> is an empty container, it will not be resolved to an XHTML element in the DOM structure. For instance, the <b:box /> is translated by the Client engine to a plain XHTML <div /> element. The <e:fragment /> tag doesn't have such a template.

The reason this works with <xi:include href="myfragment.xml" /> is because we replace the xi:include with the content from the referenced file. Since we know for sure that the <xi:include /> is not your document root node (because else it would not be processed by the Client engine), we can safely ignore the <e:fragment />.

With bb.command.load, you could theoretically replace the document root with the loaded content. If we were to ignore the <e:fragment />, this could possibly result in having an invalid DOM structure if the <e:fragment /> has multiple child elements. Since only one root element is allowed, ignoring the <e:fragment /> means creating invalid XML.

However, there are a view things that can be improved from our side to make this work:
First of all, there should be a more meaningful error message, instead of "K_ is null" or similar. Secondly, we can of course implement a more intelligent loading mechanism, where we check if ignoring the <e:fragment /> causes invalid XML. If that would be the case, we can throw an error, else we can simply proceed with ignoring the <e:fragment /> and loading the content.

The reason for introducing the <e:fragment /> was to allow developers to minimize the number of XHTML div elements for better performance and less user-interface issues. This goal is still valid and therefor these improvements have been recorded in our issues tracking system.

Hopefully this explanation helps in understanding the current limitations regarding <e:fragment /> and enables you to continue developing Backbase enabled applications.