Package com.facilita.fc.web
Class SelectElement
- java.lang.Object
-
- com.facilita.fc.web.HtmlElement
-
- com.facilita.fc.web.SelectElement
-
public class SelectElement extends HtmlElement
Represents an HTML select element within an HTML form. An HTML element is everything from the start tag to the end tag.A
SelectElement
is used to create a drop-down list.OptionElement
objects are used to define the available options in the list.e.g.
When the containing<select name="drink"> <option value="lemonade">Lemonade</option> <option value="coke">Coke</option> <option value="pepsi">Pepsi</option> <option value="tango">Tango</option> </select>
Form
is sent to the web server, a name/value pair will be sent which uses the name of theSelectElement
and the value of the currently selectedOptionElement
.- See Also:
Form
,OptionElement
-
-
Constructor Summary
Constructors Constructor Description SelectElement(long cPtr, boolean cMemoryOwn)
For internal use only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOptionElement(OptionElement element)
Adds anOptionElement
to the list of availableOptionElement
objects.HtmlElement
clone()
Creates a copy of this HTML element.void
delete()
static long
getCPtr(SelectElement obj)
For internal use only.int
getOptionCount()
Gets the number ofOptionElement
objects in thisSelectElement
.OptionElement
getOptionElement(int index)
Gets theOptionElement
at the specifedindex
.OptionElement
getOptionElement(java.lang.String value)
Gets theOptionElement
with the specifiedvalue
.OptionElement
getSelectedOption()
Gets theOptionElement
that is currently selected.void
insertOptionElement(int index, OptionElement element)
Inserts anOptionElement
into the list of availableOptionElement
objects.boolean
isMultiple()
Returnstrue
if it is possible to select multiple options at once.boolean
isSuccessfulControl()
Returnstrue
if thisSelectElement
currently represents a successful control.static SelectElement
makeFrom(HtmlElement htmlElement)
For internal use only.void
removeOptionElement(int index)
void
removeOptionElement(java.lang.String value)
Removes theOptionElement
with the specifiedvalue
from the list of availableOptionElement
objects.void
setSelectedOption(OptionElement element)
Sets the selected option from the list of availableOptionElement
objects.void
setSelectedOption(java.lang.String value)
Sets the selected option from the list of availableOptionElement
objects.-
Methods inherited from class com.facilita.fc.web.HtmlElement
getAfterEndTagPosition, getAfterStartTagPosition, getAttribute, getAttributes, getCharEncoding, getContent, getContentPosition, getCPtr, getId, getName, getTag, getValue, hasAttribute, isDisabled, removeAttribute, setAttribute, setAttribute, setCharEncoding, setContent, setDisabled, setId, setName, setValue
-
-
-
-
Method Detail
-
getCPtr
public static long getCPtr(SelectElement obj)
For internal use only. Of no interest to the user.- Parameters:
obj
- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
makeFrom
public static SelectElement makeFrom(HtmlElement htmlElement)
For internal use only. Of no interest to the user.- Parameters:
htmlElement
- Internal use only- Returns:
- a new SelectElement
-
delete
public void delete()
- Overrides:
delete
in classHtmlElement
-
setSelectedOption
public void setSelectedOption(java.lang.String value) throws NoSuchValueException, java.io.UnsupportedEncodingException
Sets the selected option from the list of availableOptionElement
objects. This is the option that will be sent to the web server when the form is submitted.- Parameters:
value
- the value to choose- Throws:
java.io.UnsupportedEncodingException
- The encoding is not supportedNoSuchValueException
- noOptionElement
with the specifiedvalue
exists in thisSelectElement
- See Also:
setSelectedOption(OptionElement)
,getSelectedOption()
-
getOptionElement
public OptionElement getOptionElement(java.lang.String value) throws NoSuchValueException, java.io.UnsupportedEncodingException
Gets theOptionElement
with the specifiedvalue
.<option>
tags don't contain aname
attribute, they are distinguished by the text in theirvalue
attribute instead.- Parameters:
value
- the value to look for- Returns:
- the
OptionElement
with the specifiedvalue
- Throws:
java.io.UnsupportedEncodingException
- The encoding is not supportedNoSuchValueException
- noOptionElement
with the specifiedvalue
exists in thisSelectElement
-
getOptionCount
public int getOptionCount()
Gets the number ofOptionElement
objects in thisSelectElement
.e.g.
// iterate over the options within a SelectElement for (int i = 0; i < selectElement.getOptionCount(); i++) { OptionElement optionElement = selectElement.getOptionElement(i); }
- Returns:
- the number of options available in this
SelectElement
- See Also:
getOptionElement(int)
-
getOptionElement
public OptionElement getOptionElement(int index) throws NoSuchValueException
Gets theOptionElement
at the specifedindex
.e.g.
// iterate over the options within a SelectElement for (int i = 0; i < selectElement.getOptionCount(); i++) { OptionElement optionElement = selectElement.getOptionElement(i); }
- Parameters:
index
- the index of theOptionElement
to retrieve- Returns:
- the
OptionElement
at the specifed index - Throws:
NoSuchValueException
- the specifiedindex
is outside the available range- See Also:
getOptionCount()
-
getSelectedOption
public OptionElement getSelectedOption() throws NoSuchValueException
Gets theOptionElement
that is currently selected. This is the option that will be sent to the web server when the form is submitted.- Returns:
- the
OptionElement
that is currently selected - Throws:
NoSuchValueException
- no option has been selected- See Also:
setSelectedOption(String)
,setSelectedOption(OptionElement)
-
setSelectedOption
public void setSelectedOption(OptionElement element)
Sets the selected option from the list of availableOptionElement
objects. This is the option that will be sent to the web server when the form is submitted.- Parameters:
element
- theOptionElement
to choose- See Also:
setSelectedOption(OptionElement)
,getSelectedOption()
-
isMultiple
public boolean isMultiple()
Returnstrue
if it is possible to select multiple options at once.Calling this method is equivalent to checking
if (getAttribute("multiple") == "multiple")
- Returns:
true
if multiple options can be selected at once
-
isSuccessfulControl
public boolean isSuccessfulControl()
Returnstrue
if thisSelectElement
currently represents a successful control. A successful control is one that is valid for submission, i.e. one that will be sent to the web server when the form is submitted.A
SelectElement
is successful ifgetSelectedOption()
returns anOptionElement
.- Overrides:
isSuccessfulControl
in classHtmlElement
- Returns:
true
if thisSelectElement
represents a successful control
-
clone
public HtmlElement clone()
Description copied from class:HtmlElement
Creates a copy of this HTML element.- Overrides:
clone
in classHtmlElement
- Returns:
- a new
HtmlElement
object which is an exact copy of this HTML element
-
addOptionElement
public void addOptionElement(OptionElement element)
Adds anOptionElement
to the list of availableOptionElement
objects.The new option is added to the end of the list.
- Parameters:
element
- theOptionElement
to add
-
insertOptionElement
public void insertOptionElement(int index, OptionElement element)
Inserts anOptionElement
into the list of availableOptionElement
objects.- Parameters:
index
- the index at which to insert the optionelement
- theOptionElement
to insert
-
removeOptionElement
public void removeOptionElement(int index)
- Parameters:
index
- the index in the list of theOptionElement
to remove
-
removeOptionElement
public void removeOptionElement(java.lang.String value) throws java.io.UnsupportedEncodingException
Removes theOptionElement
with the specifiedvalue
from the list of availableOptionElement
objects.- Parameters:
value
- the value of theOptionElement
to remove- Throws:
java.io.UnsupportedEncodingException
- The encoding is not supported
-
-