Email:   
Home
In This Issue
EasyPrint
Click here for the RSS feed's XML code. This is not a browser URL.
Using a reusable code approach to HTML select option lists: part III (continued)

As with the PropertiesOptionListSource, the SqlOptionListSource has two constructors. The primary constructor takes three arguments:

  • A JDBC datasource;
  • The unfiltered SQL statement;
  • The filtered SQL statement.

The alternate constructor also takes three arguments, but in place of the JDBC datasource, it accepts a String containing a JNDI datasource name. This secondary constructor will use the datasource name to obtain a datasource and then invoke the primary constructor.

Our implementation assumes that the filter is a single String, and that the filtered SQL statement is a prepared statement with a single replacement value. It also assumes that the unfiltered SQL statement has no replacement values. Filtered lists are created once and then stored in a HashMap for future reference, keyed by the String that was used a filter. This makes the process very similar to the default, unfiltered behavior of the base class. Both the filtered and the unfiltered SQL statements will need to return at least two columns, both of which must be accessible as Strings. Any other columns that might be returned will be ignored.

To create an SqlOptionListSource for your timekeeping application that allows developers to log time against their own projects, you could use something like the following code:

OptionListSource projectSource =
new SqlOptionListSource(myDataSource,
"select projId, projId from projects",
"select projId, projId from projects where assigned = ?");

To then obtain an option list for a specific logged-on developer, you would pass the developer's user ID (or other appropriate identifying String) to the filtered method using something like this:

ArrayList projectOpts = projectSource.getOptions(userId);

Now instead of getting the entire list of all projects in your drop-down, you only have to wade through those specific projects to which you have been assigned.

Now what?
Again, we've made quite a jump from where we started, but there are yet other improvements and additions that we can make. Next time, we'll take a look at the component factory concept and how you can create an OptionListSource component factory that instantiates and configures your OptionListSource objects so that your applications can be insulated from the specific configuration options used to create and configure the objects. In the meantime, feel free to experiment with different variations of your own.

Product availability and resources
For more information on Echo Technogoly Group, Inc., visit http://www.teametg.com.

For the article, "Using a reusable code approach to HTML select option lists: part II," by Jeff Chilton, visit http://www.webspherepower.com/issues/issue200310/00001123001.html.

For the article, "Using a reusable code approach to HTML select option lists," by Jeff Chilton, visit http://www.dominopower.com/issues/issue200310/00001118001.html.

H1 Easy, flexible article reprints ZATZ now offers a quick, easy, flexible and inexpensive way to use article reprints in your marketing and promotion efforts. You can now get article reprints for a one-time fee of only $200. For details, visit http://mediakit.zatz.com/reprints.

Jeff Chilton is Vice President of Fulfillment at Echo Technology Group, Inc., an IT consulting firm that specializes in enterprise-focused best practices. He can be reached at jchilton@teametg.com.




[ Prev ]

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
-- Advertisement --

EASY DEDICATED AND VIRTUAL DEDICATED SERVERS FOR AS LOW AS $67.99 PER MONTH
Customize and configure your own dedicated server. Simply choose one of our popular plans or select your own Linux or Windows server and plan options.

NO LONG WAITS. Server provisioned within hours.

Tap here now and be up and running with your own server tonight.

Copyright © 2008, ZATZ Publishing. All rights reserved worldwide.
Editor's Login