Thanks for the code, it worked ... However, how do I maintain the order of the selection list? The code example Robert put together worked beautifully but my Selection List was out of order... Many Thanks: Alex Restrepo -----Original Message----- From: Robert Burrell Donkin [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 01, 2001 12:20 PM To: [EMAIL PROTECTED] Subject: Re: Adding element to the begiining of an selection list and selecting an element by index "RESTREPO, ALEXANDER G [Non-Pharmacia/1000]" wrote: > Hello All: > > I would first of all like to > thanks Robert for answering my posting. > I really appreciate it. However, if > there is any source code that may help > me I would really appreciate it. OK. i've included source this time. > However, I would like to add something to > the beginning of the select list, since I > want to be able to change the first item > dynamically. I was using htmlKona from weblogic > before and I used to be able to do the following, > > "addHeadMultiElement(optionElement);" as far as i know, there isn't any direct way to do this. (it's not impossible that functionality could be added relatively easily.) the approach in ecs is to assign a hashcode to the element you want to find later. if you're looking for a dirty hack, then move all the elements into temporary storage and add them back. eg. Option addMeFirst; Select select; Vector temp = new Vector(); for (Enumeration en=select.elements();en.hasMoreElements();) { temp.addElement(en.nextElement()); } //remove all elements for (Enumeration en=temp.elements();en.hasMoreElements();) { select.removeElementFromRegistry((org.apache.ecs.Element)en.nextElement()); } //***HERE*** //add new head select.addElement(addMeFirst); //add old elements for (Enumeration en=temp.elements();en.hasMoreElements();) { select.addElement((org.apache.ecs.Element)en.nextElement()); } there is one thing to watch - and that is that text is an element, so you might need to add the new option as soon as you find the first option. eg. something like (this hasn't been tested) //***HERE*** //add old elements boolean first=true; for (Enumeration en=temp.elements();en.hasMoreElements();) { org.apache.ecs.Element next=en.nextElement(); if ( first && next instanceof Option) { first=false; select.addElement(addMeFirst); } select.addElement(next); } > In addition, Is there a way that I can > get the text and value of an option element > for a select object. not directly. you need to use getAttribute("value") and getAttribute("label"). (i have source which i was playing about which has these getters so i might submit a patch.) > For example in htmlKona I used to be able to: > (Basically I am trying to translate the > following method to use ECS but I have > had no luck. As you can see, I want to create > copies of previously created dropdowns. > I am placing ? next to the lines which > I would like to know how to translate to ECS.) > > private synchronized Select cloneDropdown(String name) throws Exception > { > Select dd = (Select) dropdownMap.get(name); > Select new_dd = new Select(name); > > for (int i = 0; i < dd.getNumElements(); i++) > { > OptionElement new_oe = new OptionElement(); > new_oe.setText(dd.getElementAt(i).getText());???? > new_oe.setValue(dd.getElementAt(i).getValue());???? > new_dd.addElement(new_oe); > } > > return new_dd; > } > > Thanks in advance.... you're in luck since ecs supports cloning of elements! (watch out, though, because attributes can be reordered). this works for me: private synchronized Select cloneDropdown(String name) throws Exception { return ((Select) dropdownMap.get(name)).clone(); } - robert --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Adding element to the begiining of an selection list and selecting an element by index
RESTREPO, ALEXANDER G [Non-Pharmacia/1000] Thu, 01 Mar 2001 16:12:29 -0800
- Re: Adding element to the begii... RESTREPO, ALEXANDER G [Non-Pharmacia/1000]
- Re: Adding element to the ... Stephan Nagy
