1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
<%@ page language="java" import="java.util.*, org.apache.struts.util.*"%>
3
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
4
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
5
<%@ taglib uri="/WEB-INF/struts-logic-el.tld" prefix="logic-el" %>
6
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
9
<title>Test html-el:select Tag</title>
11
String multipleValues[] =
12
{ "Multiple 0", "Multiple 1", "Multiple 2", "Multiple 3", "Multiple 4",
13
"Multiple 5", "Multiple 6", "Multiple 7", "Multiple 8", "Multiple 9" };
14
pageContext.setAttribute("multipleValues", multipleValues);
16
Vector options = new Vector();
17
options.add(new LabelValueBean("Label 0", "Value 0"));
18
options.add(new LabelValueBean("Label 1", "Value 1"));
19
options.add(new LabelValueBean("Label 2", "Value 2"));
20
options.add(new LabelValueBean("Label 3", "Value 3"));
21
options.add(new LabelValueBean("Label 4", "Value 4"));
22
options.add(new LabelValueBean("Label 5", "Value 5"));
23
options.add(new LabelValueBean("Label 6", "Value 6"));
24
options.add(new LabelValueBean("Label 7", "Value 7"));
25
options.add(new LabelValueBean("Label 8", "Value 8"));
26
options.add(new LabelValueBean("Label 9", "Value 9"));
27
pageContext.setAttribute("options", options);
30
{ "String 0", null, "String 2" };
31
pageContext.setAttribute("withNulls", withNulls);
35
<body bgcolor="white">
38
<h1>Test struts-html-el Select Tag</h1>
41
Whatever changes you make to properties should be reflected when the page
42
is redisplayed. Press "Save" to update, or "Cancel" to return to the
46
Ensure that the form bean exists before the form tag is processed. This
47
is a simple (if not entirely clean) way of ensuring that the initial
48
values assigned during bean instantiation will be available within the
49
form, since reset() will not be called when the form bean already exists.
51
The right way to fix this is to modify this webapp so that it does not
52
refer directly to JSP pages, but goes through Action classes, and to
53
either modify the TestBean class, adding an initialize() method, or to
54
have an Action class set the initial values.
56
<jsp:useBean id="testbean" scope="session" class="org.apache.struts.webapp.exercise.TestBean"/>
58
<html-el:form action="html-select.do">
59
<table border="0" width="100%">
62
<th align="right">Single Select Allowed:</th>
64
<html-el:select property="singleSelect" size="10">
65
<html-el:option value="Single 0">Single 0</html-el:option>
66
<html-el:option value="Single 1">Single 1</html-el:option>
67
<html-el:option value="Single 2">Single 2</html-el:option>
68
<html-el:option value="Single 3" disabled="${!empty pageScope}">
71
<html-el:option value="Single 4">Single 4</html-el:option>
72
<html-el:option value="Single 5">Single 5</html-el:option>
73
<html-el:option value="Single 6">Single 6</html-el:option>
74
<html-el:option value="Single 7">Single 7</html-el:option>
75
<html-el:option value="Single 8">Single 8</html-el:option>
76
<html-el:option value="Single 9" styleId="flork">Single 9</html-el:option>
82
<th align="right">Multiple Select Allowed:</th>
84
<html-el:select property="multipleSelect" size="10" multiple="true">
85
<html-el:options name="multipleValues" labelName="multipleValues"/>
91
<th align="right">Multiple Select From A Collection (Using <html-el:options>):</th>
93
<html-el:select property="collectionSelect" size="10" multiple="true">
94
<html-el:options collection="options" property="value" labelProperty="label"/>
100
<th align="right">Multiple Select From A Collection (Using <html-el:optionsCollection>):</th>
102
<html-el:select property="beanCollectionSelect" size="10" multiple="true">
103
<html-el:optionsCollection name="testbean" property="beanCollection"
104
filter="${empty pageScope}"/>
111
Collection with null labels and values:
114
<html-el:select property="withNulls" size="3">
115
<html-el:options name="withNulls" labelName="withNulls"
116
filter="${empty pageScope}" />
126
<html-el:select disabled="${!empty pageScope}"
127
property="withNulls" size="3">
128
<html-el:options name="withNulls" labelName="withNulls"
129
filter="${empty pageScope}" />
136
<html-el:submit>Save</html-el:submit>
139
<html-el:reset>Reset</html-el:reset>
140
<html-el:cancel>Cancel</html-el:cancel>