Database Reference
In-Depth Information
size_info = get_enumorset_info ( conn , 'cookbook' , 'cow_order' , 'size' )
print ( make_radio_group ( 'size' ,
size_info [ 'values' ],
size_info [ 'values' ],
size_info [ 'default' ],
True )) # display items vertically
print ( make_popup_menu ( 'size' ,
size_info [ 'values' ],
size_info [ 'values' ],
size_info [ 'default' ]))
When you use ENUM values like this to create list elements, values are displayed in the
order they are listed in the column definition. To produce a different display order, sort
the values appropriately.
To demonstrate how to process column metadata to generate form elements in JSP
pages, I'll use a function embedded into the page. A better approach would be to write
a custom action in a tag library that maps onto a class that returns the information, but
custom tag writing is beyond the scope of this topic. The examples take the following
approach instead:
1. Use JSTL tags to query INFORMATION_SCHEMA for the ENUM column definition and
move the definition into page context.
2. Invoke a function that extracts the definition from page context, parses it into an
array of individual enumeration values, and moves the array back into page context.
3. Access the array using a JSTL iterator that displays each of its values as a list item.
For each value, compare it to the column's default value and mark it as the initially
selected item if it's the same.
The function that extracts legal values from an ENUM or SET column definition is named
getEnumOrSetValues() . Place it into a JSP page like this:
<%@ page import = "java.util.*" %>
<%@ page import = "java.util.regex.*" %>
<%!
// declare a class method for breaking apart ENUM/SET values.
// typeDefAttr - the name of the page context attribute that contains
// the columm type definition
// valListAttr - the name of the page context attribute in which to
// store the column value list
void getEnumOrSetValues ( PageContext ctx ,
String typeDefAttr ,
String valListAttr )
{
String typeDef = ctx . getAttribute ( typeDefAttr ). toString ();
Search WWH ::




Custom Search