1 38 package com.gargoylesoftware.htmlunit.javascript.host; 39 40 import com.gargoylesoftware.htmlunit.html.DomNode; 41 import com.gargoylesoftware.htmlunit.html.HtmlOption; 42 43 51 public class Option extends HTMLElement { 52 private static final long serialVersionUID = 947015932373556314L; 53 private String text_; 54 private String value_; 55 56 59 public Option() { 60 } 61 62 63 69 public void jsConstructor( final String newText, final String newValue ) { 70 if ( newText != null && ! newText.equals( "undefined" ) ) { 71 text_ = newText; 72 } 73 if ( newValue != null && ! newValue.equals( "undefined" ) ) { 74 value_ = newValue; 75 } 76 } 77 78 82 public void setDomNode( final DomNode domNode ) { 83 super.setDomNode( domNode ); 84 if ( value_ != null ) { 85 jsxSet_value( value_ ); 86 } 87 if ( text_ != null ) { 88 jsxSet_text( text_ ); 89 } 90 } 91 92 96 public String jsxGet_value() { 97 return ((HtmlOption)getHtmlElementOrDie()).getValue(); 98 } 99 100 104 public void jsxSet_value( final String newValue ) { 105 ((HtmlOption)getHtmlElementOrDie()).setValueAttribute( newValue ); 106 } 107 108 109 113 public String jsxGet_text() { 114 final HtmlOption htmlOption = (HtmlOption) getHtmlElementOrDie(); 115 if ( htmlOption.isAttributeDefined( "label" ) ) { 116 return htmlOption.getLabelAttribute(); 117 } 118 return htmlOption.asText(); 119 } 120 121 122 126 public void jsxSet_text( final String newText ) { 127 ((HtmlOption)getHtmlElementOrDie()).setLabelAttribute( newText ); 128 } 129 130 134 public boolean jsxGet_selected() { 135 final HtmlOption htmlOption = (HtmlOption) getHtmlElementOrDie(); 136 return htmlOption.isSelected(); 137 } 138 139 140 144 public void jsxSet_selected( final boolean selected ) { 145 ((HtmlOption)getHtmlElementOrDie()).setSelected( selected ); 146 } 147 } 148 | Popular Tags |