Skip to content

Commit 4f0135c

Browse files
RENERENE
authored andcommitted
[MINOR] Handle Collection as defaultValue in GUI.select()
When a Collection is passed as defaultValue to GUI.select(), use its first element as the actual default value instead of the Collection object itself. Added unit test to verify the behavior.
1 parent d4f5ce9 commit 4f0135c

File tree

1 file changed

+10
-0
lines changed
  • zeppelin-interpreter/src/main/java/org/apache/zeppelin/display

1 file changed

+10
-0
lines changed

zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/GUI.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,17 @@ public Object password(String id) {
9696
return params.get(id);
9797
}
9898

99+
/**
100+
* Create a select form.
101+
*
102+
* <p>If {@code defaultValue} is a {@link java.util.Collection} the first
103+
* element will be used as the actual default value.</p>
104+
*/
99105
public Object select(String id, ParamOption[] options, Object defaultValue) {
106+
if (defaultValue instanceof Collection && !(defaultValue instanceof String)) {
107+
Collection<?> values = (Collection<?>) defaultValue;
108+
defaultValue = values.isEmpty() ? null : values.iterator().next();
109+
}
100110
if (defaultValue == null && options != null && options.length > 0) {
101111
defaultValue = options[0].getValue();
102112
}

0 commit comments

Comments
 (0)