Developer Tools
JDeveloper
Written By Duncan Mills, Oracle Corporation
May 2004
Oracle JDeveloper 10g, using the Oracle Application Development Framework (ADF) provides the JSP page developer with convenient way of creating drop down lists which are populated from a record collection of some sort (for instance a Business Components View Object) and which set the value for a bound field. An Example of this might be to replace a department number field on an input form with a drop down list naming the department.
There is an extensive sample showing you how to create these bound list items available on OTN:
There is also a HowTo on the same subject
Creating a Databound Drop Down List in Oracle JDeveloper 10g
This tip shows you how you can extend the technique of creating bound list by adding an entry to represent a null value, which may be required if the bound column is allowed to be null by the database schema and you need to provide users with a way of selecting that as a value in the drop down.
There are two approaches you could take to add a null value:
When you data bind a drop down list onto a page you will see the following code generated for the list tag:
<html:select property="DepartmentId">
<html:optionsCollection label="prompt" value="index" property="DepartmentId.displayData"/>
</html:select>
We can add a null value to this very simply (although the null value can only be defined to appear at the start or end of the list). To do this you just have to add an extra <html:option> tag within the <html:select> tag, which has the magic value of -1. The ADF model will interpret this as meaning set the bound column to null.
So here is the drop down list with a null value added as the first value in the list.
<html:select property="DepartmentId">
<html:option value="-1">(No Department Assigned)</html:option>
<html:optionsCollection label="prompt" value="index" property="DepartmentId.displayData"/>
</html:select>
The extra null entry will appear at the top of the list with the label (No Department Assigned)
You can extend this same techniques to radio groups which also use the list binding.
drmills v1.0 07/May/2004