logo       

Re: cloning nodes vs. creating new() ones: msg#00074

java.enhydra.xmlc

Subject: Re: cloning nodes vs. creating new() ones


Very close. The standard XMLC way to deal with adding multiple dynamic elements to the dom goes like this...

HTMLElement parentHook = xmlcObj.getElementParentHook();
HTMLElement templateRow = xmlcObj.getElementTemplateRow();
templateRow.removeAttribute("id");
Node clonedRow = null;
while (businessObject.hasMoreElements()) {
xmlcObj.setTextProductName(businessObject.getProductName());
clonedRow = templateRow.cloneNode(true);
parentHook.appendChild(clonedRow);
}
parentHook.removeChild(templateRow);

The above implies that the templateRow (whatever element it is, be it a <td>, <li>, <option>, etc...) contains something like <span id="ProductName">dummy data</span>. You keep on modifying data the XMLC-generated methods and clone the node. After all that, you get rid of the original template row, leaving only the nodes you inserted containing real data. Note that we remove the id attribute of the template row before doing any cloning since we don't want to have a bunch of cloned nodes with the same id. This would result in invalid HTML/XHTML.

Hope that makes sense. Note how the methodology above makes heavy use of template hooks using id's. This makes the code more robust by have an absolute reference to particular elements which can be checked at compile time. Counting on getFirstChild() and such to get to nodes that you assume to be there can fail if the template designer neglects to structure things as you expect or leaves certain things out that you assumed would be there.

Jake

At 11:03 AM 9/15/2003 -0700, you wrote:
In my HTML I have a dropdown list with one teacher option. I'm using cloneNode() to create another <option> element and calling cloneNode() on that teacher's <option> to create the text that goes <option>right here</option>. I'm using cloneNode() because I don't know how to go about creating a new object that implements HTMLOptionElement. Is the way I'm doing this how its supposed to be done, by using the w3c API, or is there a better way to instantiate new XMLC specific objects and add them to the HTMLSelectElement?
Thanks,
-M@

HTMLSelectElement teacherDropdown = form.getElementTeacherDropdown();
HTMLOptionElement teacher1 = form.getElementTeacherOption();
HTMLOptionElement teacher2 = (HTMLOptionElement) teacher1.cloneNode(false);

teacher2.appendChild(teacher1.getFirstChild().cloneNode(false));
teacher2.getFirstChild().setNodeValue("Mr. Snyde");
teacher2.setValue("2");

_______________________________________________
XMLC mailing list
XMLC@xxxxxxxxxxx
http://www.enhydra.org/mailman/listinfo.cgi/xmlc


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise