logo       


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

Subject: Re: cloning nodes vs. creating new() ones
Thanks, Jake. I tried to restructure my code to be more similar to what you had, but still ended up with doing it not much different than I had before. This time I populate the list of teachers from a static list:

                HTMLSelectElement teacherDropdown = 
form.getElementTeacherDropdown();
                HTMLOptionElement teacherName = form.getElementTeacherName();
                teacherName.removeAttribute("id");
String[] teachers = new String[] { "Mrs. Wormwood", "Mr. Snyde", "Ms. Ratchet" };
                for(int i = 0;i < teachers.length;i++){
HTMLOptionElement teacherClone = (HTMLOptionElement) teacherName.cloneNode(true);
                        teacherClone.setValue(new Integer(i).toString());
                        teacherClone.setLabel(teachers[i]);
                        teacherClone.getFirstChild().setNodeValue(teachers[i]);
                        teacherDropdown.add(teacherClone, null);
                }
                teacherDropdown.removeChild(teacherName);

I still can't seem to get away from using getFirstChild() to get ahold of the text inside the <option> tag, like so:

<option id="teacherName">Mrs. Wormwood</option>

How do you access the "Mrs. Wormwood" part? My understanding is that it is a child node of the <option> tag. Calling teacherClone.setNodeValue("foo") didn't do anything. What node should that be setting to "foo" when I call that? Is there a way to make up a new node to add to the <option> tag? It seems that if I have

<option id="teacherName"></option>

that getFirstChild() returns null. How can I expect to add text there if there isn't an existing node for me to clone?

  Also I tried to do use the <span> tag, as you mentioned, in my HTML:

<option id="teacherName"><span id="teacher">Mrs. Wormwood</span></option>

When I run xmlc as

xmlc -keep -class org.poindextrose.school.xmlc.AddStudentForm -sourceout ../WEB-INF/classes/ -nocompile -delete-class "DELETE_ME" addStudent.html

I see

addStudent.html:61: Warning: discarding unexpected <span>
addStudent.html:61: Warning: discarding unexpected plain text
addStudent.html:61: Warning: discarding unexpected </span>
addStudent.html:61: Warning: discarding unexpected </option>

and no code gets generated for the 'teacher' span element.
  Thanks,
    -M@

On Monday, September 15, 2003, at 01:11  PM, Jacob Kjome wrote:


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

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



Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
Search:
Java, servers, webhosts, VoIP...
more...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe