Steve,
You can inject COMPONENTS into an XPage at runtime. I'm not sure if you can inject a custom control into an XPage using this technique but I guess theoretically it is a java class somewhere within the nsf so it may be possible. So, let's say you have an <xp:div id="div1"> component on the page somewhere and you would like to put an <xp:section> component within that div. In the beforePageLoad or afterPageLoad event of the page you could do something like:
var navDiv = getComponent("div1");
var newSection = new com.ibm.xsp.component.xp.XspSection();
newSection.setHeader("The Header of the Section");
newSection.setInitClosed(false);
var contentDiv = new com.ibm.xsp.component.xp.XspDiv();
var divContent = new com.ibm.xsp.component.xp.XspOutputText();
divContent.setContentType("HTML");
divContent.setValue("<p>Some HTML of your choice</p>");
contentDiv.getChildren().add(divContent);
newSection.getChildren().add(contentDiv);
navDiv.getChildren().add(newSection);
This would do the following:
- Get the <xp:div> that's already on the page
- Create a new <xp:section>
- Set it's header to "The Header of the Section"
- Set it's initClosed property to false
- Create a new <xp:div> component
- Create a computed text component
- Set the computed text content type to "HTML"
- Set the Computed Text component's value to "Some HTML of your choice"
- Add the Computed Text to the new div
- Add the div to the section
- Add the section to the existing div
Now, you can't really add text or straight HTML to the page using this method, but you can create components, manipulate their properties and place those on the page. Also, while this is quite a bit of code to do something rather simple, it is very flexible and powerful. Place this in a Server Side Javascript library as a function or within an object and with some imagination and time could become quite reusable to perform certain repetitive tasks. In order to find all the properties and methods of components visit
http://www.openntf.org/xspext/xpages%20extension%20library%20documentation.nsf/xpages-doc/Controls.html. This documents almost all of the components available in both the core XSP model and in the Extension Library. Hope this helps.
Keith