Class ListBoxModel
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<ListBoxModel.Option>
-
- hudson.util.ListBoxModel
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<ListBoxModel.Option>
,Collection<ListBoxModel.Option>
,List<ListBoxModel.Option>
,RandomAccess
,org.kohsuke.stapler.HttpResponse
@ExportedBean public class ListBoxModel extends ArrayList<ListBoxModel.Option> implements org.kohsuke.stapler.HttpResponse
Model object of dynamically filled list box.Usage
The dynamic list box support allows the SELECT element to change its options dynamically by using the values given by the server.
To use this, HTML needs to declare the SELECT element:
<xmp> <select id='foo'> <option>Fetching values...</option> </select> </xmp>
The SELECT element may have initial option values (in fact in most cases having initial values are desirable to avoid the client from submitting the form before the AJAX call updates the SELECT element.) It should also have an ID (although if you can get to the DOM element by other means, that's fine, too.)
Other parts of the HTML can initiate the SELECT element update by using the "updateListBox" function, defined in
hudson-behavior.js
. The following example does it when the value of the textbox changes:<xmp> <input type="textbox" onchange="updateListBox('list','optionValues?value='+encode(this.value))"/> </xmp>
The first argument is the SELECT element or the ID of it (see Prototype.js
$(...)
function.) The second argument is the URL that returns the options list.The URL usually maps to the
doXXX
method on the server, which usesListBoxModel
for producing option values. See the following example:public ListBoxModel doOptionValues(@QueryParameter("value") String value) throws IOException, ServletException { ListBoxModel m = new ListBoxModel(); for (int i=0; i<5; i++) m.add(value+i,value+i); // make the third option selected initially m.get(3).selected = true; return m; }
- Since:
- 1.123
- Author:
- Kohsuke Kawaguchi
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ListBoxModel.Option
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description ListBoxModel()
ListBoxModel(int initialCapacity)
ListBoxModel(ListBoxModel.Option... data)
ListBoxModel(Collection<ListBoxModel.Option> c)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(ModelObject usedForDisplayName, String value)
ListBoxModel
add(String nameAndValue)
A version of theadd(String, String)
method where the display name and the value are the same.void
add(String displayName, String value)
void
generateResponse(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, Object node)
ListBoxModel.Option[]
values()
Deprecated.Exposed for stapler.void
writeTo(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from class java.util.AbstractCollection
containsAll, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.List
containsAll
-
-
-
-
Constructor Detail
-
ListBoxModel
public ListBoxModel(int initialCapacity)
-
ListBoxModel
public ListBoxModel()
-
ListBoxModel
public ListBoxModel(Collection<ListBoxModel.Option> c)
-
ListBoxModel
public ListBoxModel(ListBoxModel.Option... data)
-
-
Method Detail
-
add
public void add(ModelObject usedForDisplayName, @NonNull String value)
-
add
public ListBoxModel add(@NonNull String nameAndValue)
A version of theadd(String, String)
method where the display name and the value are the same.
-
writeTo
public void writeTo(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
- Throws:
IOException
javax.servlet.ServletException
-
generateResponse
public void generateResponse(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, Object node) throws IOException, javax.servlet.ServletException
- Specified by:
generateResponse
in interfaceorg.kohsuke.stapler.HttpResponse
- Throws:
IOException
javax.servlet.ServletException
-
values
@Exported @Deprecated public ListBoxModel.Option[] values()
Deprecated.Exposed for stapler. Not meant for programmatic consumption.
-
-