1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.dom;
16
17 import org.htmlunit.corejs.javascript.Scriptable;
18 import org.htmlunit.html.DomNode;
19 import org.htmlunit.html.HtmlRadioButtonInput;
20 import org.htmlunit.javascript.JavaScriptEngine;
21 import org.htmlunit.javascript.configuration.JsxClass;
22 import org.htmlunit.javascript.configuration.JsxConstructor;
23 import org.htmlunit.javascript.configuration.JsxGetter;
24 import org.htmlunit.javascript.configuration.JsxSetter;
25 import org.htmlunit.javascript.configuration.JsxSymbol;
26
27 import java.util.List;
28
29 import static org.htmlunit.html.DomElement.ATTRIBUTE_NOT_DEFINED;
30
31
32
33
34
35
36
37
38 @JsxClass
39 public class RadioNodeList extends NodeList {
40
41
42
43
44 public RadioNodeList() {
45 super();
46 }
47
48
49
50
51
52
53 public RadioNodeList(final DomNode domNode) {
54 super(domNode, true);
55 }
56
57
58
59
60
61
62
63
64 public RadioNodeList(final DomNode domNode, final boolean attributeChangeSensitive) {
65 super(domNode, attributeChangeSensitive);
66 }
67
68
69
70
71
72
73 public RadioNodeList(final DomNode domNode, final List<DomNode> initialElements) {
74 super(domNode, initialElements);
75 }
76
77
78
79
80 @Override
81 @JsxConstructor
82 public void jsConstructor() {
83 super.jsConstructor();
84 }
85
86
87
88
89
90
91
92 @JsxGetter
93 public String getValue() {
94 for (final DomNode node : getElements()) {
95 if (node instanceof HtmlRadioButtonInput && ((HtmlRadioButtonInput) node).isChecked()) {
96 final String value = ((HtmlRadioButtonInput) node).getValueAttribute();
97 return value == ATTRIBUTE_NOT_DEFINED ? "on" : value;
98 }
99 }
100
101 return "";
102 }
103
104
105
106
107
108
109 @JsxSetter
110 public void setValue(final String newValue) {
111 for (final DomNode node : getElements()) {
112 if (node instanceof HtmlRadioButtonInput) {
113 String value = ((HtmlRadioButtonInput) node).getValueAttribute();
114 if (value == ATTRIBUTE_NOT_DEFINED) {
115 value = "on";
116 }
117 if (newValue.equals(value)) {
118 ((HtmlRadioButtonInput) node).setChecked(true);
119 break;
120 }
121 }
122 }
123 }
124
125
126
127
128 @JsxSymbol
129 public Scriptable iterator() {
130 return JavaScriptEngine.newArrayIteratorTypeValues(getParentScope(), this);
131 }
132 }