1 13 package info.magnolia.cms.gui.control; 14 15 import info.magnolia.cms.core.Content; 16 17 import java.util.ArrayList ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 21 import org.apache.commons.lang.StringUtils; 22 23 24 28 public class Select extends ControlSuper { 29 30 private List options = new ArrayList (); 31 32 public Select() { 33 } 34 35 public Select(String name, String value) { 36 super(name, value); 37 } 38 39 public Select(String name, Content websiteNode) { 40 super(name, websiteNode); 41 } 42 43 public void setOptions(List l) { 44 this.options = l; 45 } 46 47 public void setOptions(SelectOption option) { 48 this.getOptions().add(option); 49 } 50 51 public void setOptions(String label, String value) { 52 this.getOptions().add(new SelectOption(label, value)); 53 } 54 55 public List getOptions() { 56 return this.options; 57 } 58 59 public String getHtml() { 60 StringBuffer html = new StringBuffer (); 61 html.append("<select"); html.append(" name=\"" + this.getName() + "\""); html.append(" id=\"" + this.getName() + "\""); html.append(this.getHtmlCssClass()); 65 html.append(this.getHtmlCssStyles()); 66 html.append(this.getHtmlEvents()); 67 html.append(">"); Iterator it = this.getOptions().iterator(); 69 while (it.hasNext()) { 70 SelectOption o = (SelectOption) it.next(); 71 if (StringUtils.isNotEmpty(this.getValue())) { 72 if (this.getValue().equals(o.getValue())) { 73 o.setSelected(true); 74 } 75 else { 76 o.setSelected(false); 77 } 78 } 79 html.append(o.getHtml()); 80 } 81 html.append("</select>"); if (this.getSaveInfo()) { 83 html.append(this.getHtmlSaveInfo()); 84 } 85 return html.toString(); 86 } 87 } | Popular Tags |