Struts 1 Examples html:checkbox, html:multibox, html:select, html:option, ….
This tutorial package includes working examples and descriptions for the following Struts tags.
Downloads
http://www.laliluna.de/download/struts-html-select-en.pdf
http://www.laliluna.de/download/struts-html-checkbox-en.pdf
http://www.laliluna.de/download/struts-html-options-en.pdf
http://www.laliluna.de/download/struts-html-radio-en.pdf
http://www.laliluna.de/download/struts-html-multibox-en.pdf
http://www.laliluna.de/download/struts-html-optionscollection-en.pdf
http://www.laliluna.de/download/struts-html-option-en.pdf
Sources
http://www.laliluna.de/download/struts-1-examples.zip
The
<html:checkbox> element
The
<html:checkbox> element is used with an associated property of
typ boolean. It renders a HTML <input> element of typ checkbox.
The
following example shows the source code of the JSP file.
<html:checkbox property="checked">Label</html:checkbox>
The
following HTML source code is rendered at runtime.
<input type=“checkbox” name=“checked” value=“on”>Label
<html:multibox>
The
<html:multibox> element
is used to manage multiple checkbox elements, for example in lists.
The value, which will be transfered to the server from a selected
checkbox, can be any value of type string. The associated property in
the form-bean is an array of type string, which holds a list of
selected values after submitting the form.
The
following examples shows the source code of the JSP file:
<html:multibox property=“selectedItems” value=“1”> Maria
The
<html:select> element
The
<html:select> renders a HTML <select>
element. A property of a form bean associated with this element,
which holds the value if the element is submitted to the server
The
<html:select> element works in two different modes:
Single
selection of an element-
Multiple
selection of elements
The
following example shows the source code of the jsp file.
<html:select property="selectedItem"><br> <html:option value="Maria">Maria</html:option><br> <html:option value="Klaus">Klaus</html:option><br></html:select>
The
following HTML source code is rendered at runtime.
<select name=“selectedItem”>
<option value=“1”>Marie</option>
<option value=“2”>Klaus</option>
</select>
The
<html:option> element
The
<html:option> element is a part of the <html:select>
element and must be nested inside this element. It can be used
multiple times inside the <html:select> element. The
<html:option> renders a HTML <option> element at
runtime.
The
following example shows the source code of the JSP file:
<html:select property="selectedItem"><br> <html:option value="Marie">Marie</html:option><br> <html:option value="Klaus">Klaus</html:option><br></html:select>
The
following HTML source code will be rendered.
<select name=“selectedItem”>
<option value=“Marie”>Marie</option>
<option value=“Klaus”>Klaus</option>
</select>
The
<html:options> element
The
<html:options> element is only valid when nested inside
a <html:select> element. Renders a HTML <option>
element. The element is used to display data of lists (arrays,
collections) inside a select element. This tag can be used multiple
times within a single <html:select> element.
The
following example shows the source code of the JSP file.
<html:select property=“selectedItem”>
<html:options collection=“customers” property=“id” labelProperty=“name” />
</html:select>
The
following HTML source code is rendered at runtime.
<select name=“selectedItem”>
<option value=“1”>Marie</option>
<option value=“2”>Klaus</option>
</select>
The
<html:optionscollection> element
The
<html:optionscollection> element is only valid nested
inside a <html:select> element. It renders a HTML
<option> element. The <html:optionscollection>
element is used to output lists (arrays, collections) for a HTML
select field. This tag differs from the <i><span ><html:options></span></i>
tag in that it makes more consistent use of the <i><span >name</span></i>
and <i><span >property</span></i>
attributes, and allows the collection to be more easily obtained from
the enclosing form bean.
The
following examples shows the source code of the JSP file:
<html:select property=“selectedItem”>
<html:options collection=“customers” value=“id” label=“name” />
</html:select>
The
following HTML source code is rendered at runtime:
<select name=“selectedItem”>
<option value=“1”>Marie</option>
<option value=“2”>Klaus</option>
</select>
The
<html:radio> element
It
renders a HTML <radio> Element. You assign a property of the
form-bean to this element. <html:radio> elements with
the same property will be grouped. It is possible to use a
<html:radio> element inside an iteration.
The
following example shows the source code of the JSP file:
<html:radio property=“selectedItem” value=“Maria” />
<html:radio property=“selectedItem” value=“Klaus” />
The
following HTML source code will be rendered.
<input type=“radio” name=“selectedItem” value=“Maria”>
<input type=“radio” name=“selectedItem” value=“Klaus”>