logo       

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

java.enhydra.xmlc

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

On Tuesday, September 16, 2003, at 01:43 AM, Richard Kunze wrote:

On Tuesday 16 September 2003 10:20, Matthew Hixson wrote:
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?

Use the generated method "setTextTeacherName(String)". This sets the content
of the first descendant of the node with id "teacherName". In your example,
thats the first child (i.e. the same node you are using), but the difference
is that "setText....()" doesn't break the template if e.g. the designer
decides to make the text bold.

Thanks, Richard. I was trying to muck with either teacherName or teacherClone directly and wasn't having much luck. Now I get that I need to modify the original template and then clone it.
Thanks,
-M@


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

News | FAQ | advertise