|
Re: cloning nodes vs. creating new() ones: msg#00081java.enhydra.xmlc
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. > 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. That's right. There isn't any child node in this case. Simply add a dummy text to the template. Hope this helps, Richard -- Richard Kunze [ t]ivano Software, Bahnhofstr. 18, 63263 Neu-Isenburg Tel.: +49 6102 80 99 07 - 0, Fax.: +49 6102 80 99 07 - 1 http://www.tivano.de
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: cloning nodes vs. creating new() ones, Matthew Hixson |
|---|---|
| Next by Date: | Re: cloning nodes vs. creating new() ones, Petr Stehlik |
| Previous by Thread: | Re: cloning nodes vs. creating new() ones, Matthew Hixson |
| Next by Thread: | Re: cloning nodes vs. creating new() ones, Jacob Kjome |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |