Database Reference
In-Depth Information
For a multiple-pick scrolling list, do this:
<select name= "accessories" size= "3" multiple= "multiple" >
<c:forEach items= "${values}" var= "val" >
<option
value= "<c:out value=" ${val}" /> "
<c:forEach items= "${defList}" var= "defaultVal" >
<c:if test= "${val == defaultVal}" > selected="selected" </c:if>
</c:forEach>
> <c:out value= "${val}" /></option>
</c:forEach>
</select>
20.4. Loading Database Content into a Form
Problem
You want to display a form but initialize it using the contents of a database record, to
present a record-editing form.
Solution
Generate the form as you usually would, but populate it with database content. That is,
instead of setting the form fields to their usual defaults, set them to values retrieved
from the database.
Discussion
The examples in earlier recipes that show how to generate form fields have either sup‐
plied no default value or have used the default value as specified in an ENUM or SET column
definition. That's appropriate for presenting a “blank” form that you expect the user to
fill in. However, for applications that present a web-based interface for record editing,
it's more likely that you'd want to fill in the form using the content of an existing record
for the initial values. This section discusses how to do that.
The examples shown here illustrate how to generate an editing form for rows from the
cow_order table. Normally, you would permit the user to specify which record to edit.
For simplicity, assume the use of a record that has an id value of 1 , with the following
contents:
mysql> SELECT * FROM cow_order WHERE id = 1\G
*************************** 1. row ***************************
id: 1
color: Black & White
size: large
accessories: cow bell,nose ring
cust_name: Farmer Brown
cust_street: 123 Elm St.
Search WWH ::




Custom Search