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
SelectElementis used to create a drop-down list.OptionElementobjects 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>Formis sent to the web server, a name/value pair will be sent which uses the name of theSelectElementand 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 voidaddOptionElement(OptionElement element)Adds anOptionElementto the list of availableOptionElementobjects.HtmlElementclone()Creates a copy of this HTML element.voiddelete()static longgetCPtr(SelectElement obj)For internal use only.intgetOptionCount()Gets the number ofOptionElementobjects in thisSelectElement.OptionElementgetOptionElement(int index)Gets theOptionElementat the specifedindex.OptionElementgetOptionElement(java.lang.String value)Gets theOptionElementwith the specifiedvalue.OptionElementgetSelectedOption()Gets theOptionElementthat is currently selected.voidinsertOptionElement(int index, OptionElement element)Inserts anOptionElementinto the list of availableOptionElementobjects.booleanisMultiple()Returnstrueif it is possible to select multiple options at once.booleanisSuccessfulControl()Returnstrueif thisSelectElementcurrently represents a successful control.static SelectElementmakeFrom(HtmlElement htmlElement)For internal use only.voidremoveOptionElement(int index)voidremoveOptionElement(java.lang.String value)Removes theOptionElementwith the specifiedvaluefrom the list of availableOptionElementobjects.voidsetSelectedOption(OptionElement element)Sets the selected option from the list of availableOptionElementobjects.voidsetSelectedOption(java.lang.String value)Sets the selected option from the list of availableOptionElementobjects.-
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:
deletein classHtmlElement
-
setSelectedOption
public void setSelectedOption(java.lang.String value) throws NoSuchValueException, java.io.UnsupportedEncodingExceptionSets the selected option from the list of availableOptionElementobjects. 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- noOptionElementwith the specifiedvalueexists in thisSelectElement- See Also:
setSelectedOption(OptionElement),getSelectedOption()
-
getOptionElement
public OptionElement getOptionElement(java.lang.String value) throws NoSuchValueException, java.io.UnsupportedEncodingException
Gets theOptionElementwith the specifiedvalue.<option>tags don't contain anameattribute, they are distinguished by the text in theirvalueattribute instead.- Parameters:
value- the value to look for- Returns:
- the
OptionElementwith the specifiedvalue - Throws:
java.io.UnsupportedEncodingException- The encoding is not supportedNoSuchValueException- noOptionElementwith the specifiedvalueexists in thisSelectElement
-
getOptionCount
public int getOptionCount()
Gets the number ofOptionElementobjects 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 theOptionElementat 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 theOptionElementto retrieve- Returns:
- the
OptionElementat the specifed index - Throws:
NoSuchValueException- the specifiedindexis outside the available range- See Also:
getOptionCount()
-
getSelectedOption
public OptionElement getSelectedOption() throws NoSuchValueException
Gets theOptionElementthat is currently selected. This is the option that will be sent to the web server when the form is submitted.- Returns:
- the
OptionElementthat 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 availableOptionElementobjects. This is the option that will be sent to the web server when the form is submitted.- Parameters:
element- theOptionElementto choose- See Also:
setSelectedOption(OptionElement),getSelectedOption()
-
isMultiple
public boolean isMultiple()
Returnstrueif it is possible to select multiple options at once.Calling this method is equivalent to checking
if (getAttribute("multiple") == "multiple")- Returns:
trueif multiple options can be selected at once
-
isSuccessfulControl
public boolean isSuccessfulControl()
Returnstrueif thisSelectElementcurrently 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
SelectElementis successful ifgetSelectedOption()returns anOptionElement.- Overrides:
isSuccessfulControlin classHtmlElement- Returns:
trueif thisSelectElementrepresents a successful control
-
clone
public HtmlElement clone()
Description copied from class:HtmlElementCreates a copy of this HTML element.- Overrides:
clonein classHtmlElement- Returns:
- a new
HtmlElementobject which is an exact copy of this HTML element
-
addOptionElement
public void addOptionElement(OptionElement element)
Adds anOptionElementto the list of availableOptionElementobjects.The new option is added to the end of the list.
- Parameters:
element- theOptionElementto add
-
insertOptionElement
public void insertOptionElement(int index, OptionElement element)Inserts anOptionElementinto the list of availableOptionElementobjects.- Parameters:
index- the index at which to insert the optionelement- theOptionElementto insert
-
removeOptionElement
public void removeOptionElement(int index)
- Parameters:
index- the index in the list of theOptionElementto remove
-
removeOptionElement
public void removeOptionElement(java.lang.String value) throws java.io.UnsupportedEncodingExceptionRemoves theOptionElementwith the specifiedvaluefrom the list of availableOptionElementobjects.- Parameters:
value- the value of theOptionElementto remove- Throws:
java.io.UnsupportedEncodingException- The encoding is not supported
-
-