What is CoffeeFilter?
CoffeeFilter
is a lightweight java validation and data object creation framework
that works off of incoming request URL parameters. It is intended for JSP web application.
CoffeeFilter is basically a Filter pattern product.
In it's most basic usage
CoffeeFilter
can be used to validate that
parameters required for the view are included in the request URL string.
In more advanced usage, it can generate data objects based on URL parameters before hitting
the view; ie pre-processing data based on URL parameters to resolve data. Data objects are really
just JavaBeans that implement an interface.
Why use CoffeeFilter?
I've thought about this a lot after a friend, ML, smartly questioned the intent behind this
framework... It is two fold:
-
Create a URL parameter validation framework that was simple to use. Basically, the
idea is that parameter validation in every page is overhead that you don't need to
deal with! URL parameter validation is easily (re)moved into a central location that
works without having to know about your page layouts, ie it works based on config files
and dependency injection.
-
The URL parameter validation is of, admittidly, little use; basically, why bother with
URL parameters if you could just create a separate page, eh? Almost. What if you need
to do some pre-processing based on the URL parameters before you actually hit
the page. Imagine somebody linking into a distributed application using URL parameters
that are user credentials that resolve their info (a lame example, I know).
You basically need the lookup to happen before you hit the page that will display said
info. If this is your case, then this framework could be of use.
There are a lot of other great tools out there that do similar things, but I've yet
to find one that matched my needs.
Here is a run down of pros and cons:
-
Struts
-
I use Struts all over the place, however, Struts doesn't handle robust DO instantiation
before hitting the jsp. Sure it can create bean object for you, but what if you need URL
parameters to figure out what attributes the bean should contain?
-
I guess that Struts2 has largely bundled this idea into validation rules and Interceptors,
namely the "param" and "prepare" interceptors. However, this code still works on top of Struts
(not Struts2) and would require no rewrite of legacy code in that regard. Once Struts2 becomes
mature enough, I will most likely stop development of
CoffeeFilter
.
The good thing is that my idea is the similar to their idea. What an ego boost!
-
Java Beans
-
Java beans on JSPs are ok, I guess... But you run into the same problems I outlined in the
first Struts section with populating beans based on URL parameters.
-
Spring
-
Being a Struts guy, I've never got Spring. Err, "got into Spring"...
I know that it can handle object instantiation while on a page, but don't know if it can
do much with url parameters...